#Animation
1 messages · Page 1 of 1 (latest)
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
public class zombieScript : MonoBehaviour {
private Transform goal;
private NavMeshAgent agent;
void Start () {
GetComponent<Animation>().Play ("Z_Walk");
goal = Camera.main.transform;
agent = GetComponent<NavMeshAgent>();
agent.destination = goal.position;
}
void OnTriggerEnter (Collider col)
{
Debug.Log(col);
GetComponent<CapsuleCollider>().enabled = false;
Destroy(col.gameObject);
agent.destination = gameObject.transform.position;
GetComponent<Animation>().Stop ();
GetComponent<Animation>().Play ("Z_FallingBack");
Destroy (gameObject, 6);
GameObject zombie = Instantiate(Resources.Load("zombie", typeof(GameObject))) as GameObject;
float randomX = UnityEngine.Random.Range (-12f,12f);
float constantY = .01f;
float randomZ = UnityEngine.Random.Range (-13f,13f);
zombie.transform.position = new Vector3 (randomX, constantY, randomZ);
while (Vector3.Distance (zombie.transform.position, Camera.main.transform.position) <= 3) {
randomX = UnityEngine.Random.Range (-12f,12f);
randomZ = UnityEngine.Random.Range (-13f,13f);
zombie.transform.position = new Vector3 (randomX, constantY, randomZ);
}
}
}