Let's assume; There are 5 enemies. How can I stop other enemies for 2 seconds if I kill one? I don't wanna stop player so i can't use "Time.timeScale = 0" . I mean I don't know how to use it. My enemy script; Code (CSharp): public class Enemy : MonoBehaviour { public GameObject player; public float movementSpeed = 4; void Start() { player = GameObject.FindWithTag("Player"); } void Update() { transform.LookAt(player.transform); transform.position += transform.forward * movementSpeed * Time.deltaTime; } void OnCollisionEnter (Collision col) { if (col.gameObject.tag.Equals ("Bullet")) { Destroy (col.gameObject); Destroy(transform.parent.gameObject); Destroy (this.gameObject); } } }
What do you mean by stop them? Do you want the animations to freeze, or just stop attacking the player? In any case, you'll need the enemies to have a script that can be told when they should pause, and then have them tell all the other enemies to pause when they die. FindObjectOfType<EnemyScript>() could be useful for that.
The enemies are just walking towards the player. No attacks. When I kill one, I want the others to stay in place for two seconds. Then I want them to walk back to the player.
Oh, make a cooldown timer for them. Code (csharp): public class Enemy : MonoBehaviour { public GameObject player; public float movementSpeed = 4; private float wait = 0; // Added void Start() { player = GameObject.FindWithTag("Player"); } void Update() { if(wait > 0) // Added { wait -= Time.deltaTime; return; // exit update early when our timer is active, so we don't move anymore } transform.LookAt(player.transform); transform.position += transform.forward * movementSpeed * Time.deltaTime; } void OnCollisionEnter (Collision col) { if (col.gameObject.tag.Equals ("Bullet")) { Destroy (col.gameObject); Destroy(transform.parent.gameObject); Destroy (this.gameObject); foreach(var enemy in FindObjectsOfType<Enemy>()) // Added enemy.wait = 2.0f; // this can be whatever time you want } } }