Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3.  
  4. public class Zombie : MonoBehaviour
  5. {
  6. static Animator anim;
  7. private Transform player;
  8. private Rigidbody zombie;
  9. public float speed = 1f;
  10.  
  11. void Start()
  12. {
  13. player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
  14. anim = GetComponent<Animator>();
  15. zombie = GetComponent<Rigidbody>();
  16. gameObject.GetComponent<Animator>().SetBool("isIdle", true);
  17.  
  18. }
  19.  
  20. void OnTriggerStay(Collider col)
  21. {
  22. if (col.tag == "Player")
  23. {
  24.  
  25. Vector3 direction = player.position - this.transform.position;
  26. direction.y = 0;
  27.  
  28. this.transform.rotation =
  29. Quaternion.Slerp(this.transform.rotation,
  30. Quaternion.LookRotation(direction), 0.1f);
  31. Vector3 velocity = direction * speed;
  32. anim.SetBool("isIdle", false);
  33.  
  34. if (direction.magnitude > 0.4)
  35. {
  36. zombie.velocity = Vector3.right*Time.deltaTime;
  37.  
  38.  
  39. anim.SetBool("isWalking", true);
  40. anim.SetBool("isAttacking", false);
  41. }
  42. else
  43. {
  44. anim.SetBool("isAttacking", true);
  45. anim.SetBool("isWalking", false);
  46. }
  47.  
  48. }
  49.  
  50. }
  51. void OnTriggerExit(Collider col)
  52. {
  53. if (col.tag == "Player")
  54. {
  55. anim.SetBool("isWalking", false);
  56. anim.SetBool("isIdle", true);
  57.  
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement