Hey, I made a script which is attached to a turret,
public class TurretRealScript : MonoBehaviour {
public GameObject arrowPrefab;
public GameObject Target;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Enemy")
{
Target = other.gameObject;
Instantiate(arrowPrefab,
transform.position,transform.rotation);
}
}
}
and a script attached to the object which is to be fired at the enemy once the collision is triggered
public class ArrowProjectileScript2 : MonoBehaviour {
public GameObject Target;
private Vector3 direction = Vector3.forward;
public float speed=30.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Target = GameObject.FindWithTag("Enemy");
transform.Translate(direction*speed*Time.deltaTime);
transform.LookAt(Target.transform);
}
}
So far this works fine, when the turret sphere detects a collision the arrow is fired at the enemy and my script attached to the enemy destroys the arrow on collision but must require a further 2 hits before the enemy itself is destroyed,
public class Enemy1DestroyScript : MonoBehaviour {
public int count=0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (count>2)
{
Destroy(gameObject);
}
}
void OnCollisionEnter(Collision hit)
{
if(hit.gameObject.tag=="Arrow")
{
Destroy(hit.gameObject);
count++;
}
}
}
What I would like to happen is after the first 2 secs of the arrow being fired, if there is an enemy still alive in the collison area then fire another arrow. currently an arrow is only fired when an a new enemy triggers the onTriggerEnter which is no use if some enemies require more than one arrow to be killed.
Thanks for your time!