Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [RequireComponent(typeof(NavMeshAgent))]
- public class ZombieAI : MonoBehaviour {
- private NavMeshAgent NMA;
- public GameObject player;
- public Vector3 distanceFromPlayer;
- public float timeToAttack = 2;
- private float currentTimeToAttack;
- public Animation zombieAnim;
- public AnimationClip[] animations;
- public int damage;
- public bool canUp;
- public bool canMove;
- public bool isAttacking;
- public bool isDead;
- void Start () {
- damage = Random.Range(5, 10);
- NMA = this.GetComponent<NavMeshAgent>();
- }
- void Update () {
- distanceFromPlayer = this.transform.position - player.transform.position;
- canMove = !isAttacking;
- if(currentTimeToAttack > timeToAttack) {
- currentTimeToAttack = 0;
- isAttacking = false;
- canUp = false;
- }
- // if(distanceFromPlayer.x >= -0.2f && distanceFromPlayer.x <= 0 && distanceFromPlayer.z >= -0.75f && distanceFromPlayer.y <= -0.5f && currentTimeToAttack == 0) {
- //
- // isAttacking = true;
- // Attack();
- // }
- if (canUp) {
- currentTimeToAttack += Time.deltaTime;
- }
- // if (!canMove && !isAttacking) {
- // zombieAnim.clip = animations[3];
- // zombieAnim.Play();
- // }
- if (canMove && !isDead) {
- zombieAnim.clip = animations[0];
- zombieAnim.Play();
- NMA.SetDestination(player.transform.position);
- }
- }
- private void Attack() {
- player.GetComponent<PlayerStats>().life -= damage;
- isAttacking = true;
- canUp = true;
- }
- void OnTriggerEnter(Collider other) {
- if (other.gameObject.tag == "Player") {
- canMove = false;
- zombieAnim.clip = animations[1];
- zombieAnim.Play();
- Attack();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment