// Update is called once per frame
private void Update()
{
projectileSpawn = this.transform.parent.GetChild(0).position;
rotation = this.transform.parent.GetChild(0).rotation;
ShootProjectile();
}
private void OnTriggerStay(Collider collision)
{
if (collision.tag == "Human")
{
targeter = GameObject.Find("Human-1").transform;
GameObject.Find("ProjectileSpawn").GetComponent<TurretEnemy>().SetInRange(true);
//SetInRange(true);
Debug.Log("In range of enemy turret");
}
else if (collision.tag == “Human2”) {
targeter = GameObject.Find("Human-2").transform;
GameObject.Find("ProjectileSpawn").GetComponent<TurretEnemy>().SetInRange(true);
//SetInRange(true);
Debug.Log("In range of enemy turret");
}
}
private void OnTriggerExit(Collider collision)
{
if (collision.tag == "Human2" || collision.tag == "Human")
{
GameObject.Find("ProjectileSpawn").GetComponent<TurretAI>().SetInRange(false);
// SetInRange(false);
target = null;
Debug.Log("Out of range of enemy turret");
}
} // Resets the value of TurretAI.inRange to false when the astral goes out of range (leaves box collider)
private void ShootProjectile()
{
if (inRange && Time.time > nextShot) // Provided the target is close enough and a set time has past since the last shot, shoot at target
{
nextShot = Time.time + fireRate; // Causes a time delay between each projectile being fired
Instantiate(projectile, projectileSpawn, rotation);
Debug.Log("Shots Fired!");
}
}
private void SetInRange(bool incomingValue)
{
inRange = incomingValue;
}