diff --git a/Assets/Scripts/ThrowerEnemy.cs b/Assets/Scripts/ThrowerEnemy.cs index 9703f38..131f83a 100644 --- a/Assets/Scripts/ThrowerEnemy.cs +++ b/Assets/Scripts/ThrowerEnemy.cs @@ -12,6 +12,8 @@ public class ThrowerEnemy : MonoBehaviour public float playerDistance; public GameObject GunThrow; + public bool canThrow = false; + public float throwTimer = 5; private NavMeshAgent agent; public Transform target; @@ -35,14 +37,24 @@ public class ThrowerEnemy : MonoBehaviour if (!isInside && hp != 0) MeshRenderer.material = def; + if (!canThrow) + { + throwTimer -= Time.deltaTime; + if (throwTimer < 0) + { + canThrow = true; + throwTimer = 5; + } + } } void FixedUpdate() { playerDistance = Vector3.Distance(transform.position, target.position); - if (playerDistance < 25) + if (playerDistance < 25 && canThrow) { Instantiate(GunThrow, transform); + canThrow = false; } } private void LateUpdate()