Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. using UnityEngine;
  3.  
  4.  
  5. public class Zombie : MonoBehaviour
  6. {
  7. static Animator anim;
  8. private Transform player;
  9. private Rigidbody zombie;
  10. public float speed = 1f;
  11.  
  12.  
  13.  
  14.  
  15. void Start()
  16. {
  17. player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
  18. anim = GetComponent<Animator>();
  19. zombie = GetComponent<Rigidbody>();
  20. gameObject.GetComponent<Animator>().SetBool("isIdle", true);
  21.  
  22. }
  23.  
  24. void OnTriggerStay(Collider col)
  25. {
  26. if (col.tag == "Player")
  27. {
  28.  
  29. Vector3 direction = player.position - this.transform.position;
  30. direction.y = 0;
  31.  
  32. this.transform.rotation =
  33. Quaternion.Slerp(this.transform.rotation,
  34. Quaternion.LookRotation(direction), 0.1f);
  35. Vector3 velocity = direction * speed;
  36.  
  37.  
  38. anim.SetBool("isIdle", false);
  39.  
  40. if (direction.magnitude > 0.4)
  41. {
  42. zombie.velocity = Vector3.right * Time.deltaTime;
  43. // this.transform.Translate(0, 0, 0.0075f); однако с Translate работает,но AI проходит сквозь стены,игнорируются физические свойства обьекта
  44. anim.SetBool("isWalking", true);
  45. anim.SetBool("isAttacking", false);
  46. }
  47. else
  48. {
  49. anim.SetBool("isAttacking", true);
  50. anim.SetBool("isWalking", false);
  51. }
  52.  
  53. }
  54.  
  55. }
  56. void OnTriggerExit(Collider col)
  57. {
  58. if (col.tag == "Player")
  59. {
  60. anim.SetBool("isWalking", false);
  61. anim.SetBool("isIdle", true);
  62.  
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement