Throws once every 5 seconds
This commit is contained in:
@@ -12,6 +12,8 @@ public class ThrowerEnemy : MonoBehaviour
|
|||||||
|
|
||||||
public float playerDistance;
|
public float playerDistance;
|
||||||
public GameObject GunThrow;
|
public GameObject GunThrow;
|
||||||
|
public bool canThrow = false;
|
||||||
|
public float throwTimer = 5;
|
||||||
|
|
||||||
private NavMeshAgent agent;
|
private NavMeshAgent agent;
|
||||||
public Transform target;
|
public Transform target;
|
||||||
@@ -35,14 +37,24 @@ public class ThrowerEnemy : MonoBehaviour
|
|||||||
if (!isInside && hp != 0)
|
if (!isInside && hp != 0)
|
||||||
MeshRenderer.material = def;
|
MeshRenderer.material = def;
|
||||||
|
|
||||||
|
if (!canThrow)
|
||||||
|
{
|
||||||
|
throwTimer -= Time.deltaTime;
|
||||||
|
|
||||||
|
if (throwTimer < 0)
|
||||||
|
{
|
||||||
|
canThrow = true;
|
||||||
|
throwTimer = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
playerDistance = Vector3.Distance(transform.position, target.position);
|
playerDistance = Vector3.Distance(transform.position, target.position);
|
||||||
if (playerDistance < 25)
|
if (playerDistance < 25 && canThrow)
|
||||||
{
|
{
|
||||||
Instantiate(GunThrow, transform);
|
Instantiate(GunThrow, transform);
|
||||||
|
canThrow = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LateUpdate()
|
private void LateUpdate()
|
||||||
|
|||||||
Reference in New Issue
Block a user