I am trying to destroy objects with different tag when the objects enter trigger area. The code below does not work. I am just a beginner and i hope someone can help.
c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class IngredientCheck : MonoBehaviour {
string[] tags;
List<GameObject> CorrectIngredients = new List<GameObject>();
public AudioSource correctfx;
public AudioSource wrongfx;
// Use this for initialization
void Start ()
{
tags = new string[] {"Mungbeans","BananaLeaf","GlutinousRiceflour" };
foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
{
if (tags.Contains(go.tag))
CorrectIngredients.Add(go);
}
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject(CorrectIngredients))
{
Destroy(col.gameObject, 2.0f);
correctfx.Play();
}
else
{
wrongfx.Play();
}
}
}