Throws once every 5 seconds

This commit is contained in:
Garrett Kaiser
2025-11-13 14:53:19 -08:00
parent e6616444d0
commit 07ed588643

View File

@@ -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()