Advertisement
Guest User

chase_script_1

a guest
Apr 24th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. public class Сhase : MonoBehaviour
  6. {
  7.  
  8. public Transform player;
  9. Animator Anim;
  10. public int i;
  11. public float time;
  12. // Use this for initialization
  13. void Start ()
  14. {
  15. Anim = GetComponent<Animator>();
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update ()
  20. {
  21. Vector3 direction = player.position - this.transform.position;
  22. float angle = Vector3.Angle(direction, this.transform.forward);
  23.  
  24. if (Vector3.Distance(player.position, this.transform.position) < 20 && angle < 90)
  25. {
  26. direction.y = 0;
  27. this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f*Time.deltaTime);
  28.  
  29. Anim.SetBool("isIdle", false);
  30. if (direction.magnitude > 1.5f)
  31. {
  32. this.transform.Translate(0, 0, 0.035f);
  33. Anim.SetBool("isRunning", true);
  34. Anim.SetBool("isAttacking", false);
  35. }
  36. else
  37. {
  38. Anim.SetBool("isRunning", false);
  39. Anim.SetBool("isAttacking", true);
  40. }
  41. }
  42. else
  43. {
  44. this.transform.Translate(0, 0, 0.005f);
  45. if (i == 0)
  46. {
  47. int sens = new System.Random().Next(0,2);
  48. if (sens == 0)
  49. {
  50. Anim.SetBool("isTurningLeft", true);
  51. Debug.Log(Anim.GetBool("isTurningLeft").ToString());
  52. this.transform.Rotate(new Vector3(0, -90, 0));
  53. }
  54. else
  55. {
  56. Anim.SetBool("isTurningRight", true);
  57. Debug.Log(Anim.GetBool("isTurningRight").ToString());
  58. this.transform.Rotate(new Vector3(0, 90, 0));
  59. }
  60. i = 5;
  61. time = Time.realtimeSinceStartup;
  62.  
  63. }
  64. else
  65. {
  66. Anim.SetBool("isTurningRight", false);
  67. Anim.SetBool("isTurningLeft", false);
  68. }
  69. if (Time.realtimeSinceStartup - time > 2)
  70. {
  71. --i;
  72. time = Time.realtimeSinceStartup;
  73. }
  74.  
  75. Debug.Log(i.ToString());
  76. Debug.Log("turnfalse");
  77.  
  78. Anim.SetBool("isIdle", true);
  79. Anim.SetBool("isRunning", false);
  80. Anim.SetBool("isAttacking", false);
  81. }
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement