RealiteeeyyyyTV

Untitled

Jan 13th, 2018
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5.  
  6. public class Chase : MonoBehaviour {
  7.  
  8. public Transform player;
  9. static Animator anim;
  10.  
  11. void Start ()
  12. {
  13. anim = GetComponent<Animator>();
  14. }
  15.  
  16. void Update ()
  17. {
  18. if(Vector3.Distance(player.position, this.transform.position) < 1000)
  19. {
  20. Vector3 direction = player.position - this.transform.position;
  21. direction.y = 0;
  22.  
  23. this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
  24. Quaternion.LookRotation(direction), 0.1f);
  25.  
  26. anim.SetBool("isIdle", false);
  27. if(direction.magnitude > 2.75)
  28. {
  29. this.transform.Translate(0, 0, 0.05f);
  30. anim.SetBool("isWalking", true);
  31. anim.SetBool("isAttacking", false);
  32. }
  33. else
  34. {
  35. anim.SetBool("isAttacking", true);
  36. anim.SetBool("isWalking", false);
  37. }
  38. }
  39. else
  40. {
  41. anim.SetBool("isIdle", true);
  42. anim.SetBool("isWalking", false);
  43. anim.SetBool("isAttacking", false);
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment