I have multiple gameobjects that spawn randomly prefabs and I wanna do some actions when every gameobjects detects collision. I’ve tried with CompareTag but it didn’t work.
IEnumerator waitSpawner()
{
yield return new WaitForSeconds (startWait);
while (!stop)
{
float spawnLocation=Random.Range(0,0);
randEnemy = Random.Range (0, 2);
Vector2 spawnPosition = new Vector2 (spawnLocation,transform.position.y);
bulletclone=Instantiate (answers [randEnemy], spawnPosition, Quaternion.identity) as GameObject;
yield return new WaitForSeconds (spawnWait);
}
}
This is from the first script when the prefabs are randomly spawn.
void OnTriggerEnter2D(Collider2D col)
{
if(col.CompareTag("Correct"))
{
test.text="Corect";
}
else if(col.CompareTag("Wrong"))
{
test.text="Wrong";
}
}
I don’t get any error or warning, just doesn’t work.