This doesnt apply to any one of the lecturers in particular. Just trying to take what I’ve learned and apply it to a new project.
The following code is attached to a shredder, like in the block breaker game. When either a player object, or an enemy object hits the shredder, its supposed to call the specified function in the specified objects script.
void OnTriggerEnter2D(Collider2D objtyp){
if (objtyp.gameObject.CompareTag ("Player")) {
objtyp.GetComponent<PlayerController>().killplayer();
}
if (objtyp.gameObject.CompareTag ("Enemy")) {
Debug.Log("Enemy Detected");
objtyp.GetComponent<EnemySpawner>().generateEnemy();
Destroy(objtyp.gameObject);
}
}
Now, when my player character goes through the shredder, killplayer() is successfully called. My player looses a life, and is started back at the beginning.
The problem is when an enemy falls through it.
When that happens, “Enemy Detected” is written to the log, and the enemy object is destroyed, but no new enemy is created.
Why wouldn’t generateEnemy() be called killplayer() is?
I’ve double checked script and function names.