I'm making a tower defence game and I want to make it so that when the enemies hit an obstacle or and enemy infront, that they stop. When the obstacle or enemy infront is destroyed I want them to move forward again.
I'm using node based transportation for these enemies, from the Brackeys tutorial. It's been super helpful so far, and I'm at a poitn where I want to add extra things into the game.
Just to clarify, the enemies do stop when they encounter an obstacle or other enemy, they just won't move again after. The enemies also have a rigidbody so they can detect triggers, and obstacles and enemies both have a trigger collider on them.
Code:
`
private void OnTriggerEnter(Collider col)
{
if (col.CompareTag("Obstacle") || col.CompareTag("Enemy"))
{
canMove = false;
Debug.Log("Stop");
}
}
private void OnTriggerStay(Collider col)
{
if (col.CompareTag("Obstacle") || col.CompareTag("Enemy"))
{
if (col.GetComponent().health <= 0)
{
Movement();
Debug.Log("Start Moving!");
}
}
}
`
↧