Question by
Ninjix3 · Mar 22, 2018 at 12:15 AM ·
ienumeratorresetdestroy objectkeycode
Why doesn't the prefab destroy ?
I'm making a script for a bird that will hover over the player and will result in two events. One is for destroying the bird (killing) the other is for resetting the game if the player doesn't shield itself for a certain time. However, whenever I press the "S" key nothing happens. My debug.Log response doesn't show up either any reason why?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OwlAI : MonoBehaviour { public float xSpread; public float zSpread; public float yOffset;
public float waitTime= 1f;
public Transform centerPoint;
public float rotSpeed;
public bool rotateClockwise;
float timer = 0;
// Use this for initialization
void Update()
{
timer += Time.deltaTime * rotSpeed;
Rotate ();
transform.LookAt (centerPoint);
if (Input.GetKeyDown(KeyCode.S)) {
Debug.Log ("You Challenged the Bird");
StartCoroutine (OwlDeath(waitTime));
//} else {
//StartCoroutine (ResetOwl(waitTime));
}
}
void Rotate()
{
if (rotateClockwise) {
float x = -Mathf.Cos (timer) * xSpread;
float z = Mathf.Sin (timer) * zSpread;
Vector3 pos = new Vector3 (x, yOffset, z);
transform.position = pos + centerPoint.position;
}else{
float x = Mathf.Cos (timer) * xSpread;
float z = Mathf.Sin (timer) * zSpread;
Vector3 pos = new Vector3 (x, yOffset, z);
transform.position = pos + centerPoint.position;
}
}
IEnumerator OwlDeath (float waitTime){
Debug.Log ("Death Owl Started");
yield return new WaitForSeconds (waitTime);
//Destroy (this.gameObject);
Destroy (GameObject.FindWithTag ("Owl"));
}
//IEnumerator ResetOwl (float waitTime){
//Debug.Log ("Reset Game");
//yield return new WaitForSeconds (waitTime);
//}
}
Comment