Advertisement
Guest User

Untitled

a guest
May 9th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [RequireComponent (typeof(CharacterController))]
  5.  
  6. public class JasioController : MonoBehaviour
  7. {
  8.  
  9. public Animatio animatio;
  10.  
  11. public float moveSpeed, gravity, flySpeed;
  12. private GameObject player;
  13. private CharacterController characterController;
  14. private float flyTempSpeed, flyTempTime;
  15. private Vector3 direction;
  16. private bool isFlying;
  17. public float speed = 5.0f;
  18.  
  19.  
  20.  
  21.  
  22. void Start ()
  23. {
  24. player = GameObject.FindGameObjectWithTag ("Player");
  25. characterController = player.GetComponent<CharacterController> ();
  26. isFlying = false;
  27. flyTempSpeed = 0;
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update ()
  32. {
  33.  
  34. }
  35.  
  36. // void OnMouseDown ()
  37. // {
  38. // //hero.rigidbody.velocity = new Vector3 ( hero.transform.position.x, hero.transform.position.y,hero.transform.position.z+20);
  39. // if (i == 0) {
  40. // StartCoroutine (doMoveToPoint (GameObject.FindGameObjectWithTag ("Jablko")));
  41. // i++;
  42. // } else
  43. // StartCoroutine (doMoveToPoint (GameObject.FindGameObjectWithTag ("Kompostownik")));
  44. // }
  45.  
  46. // void OnMouseDown ()
  47. // {
  48. // //hero.rigidbody.velocity = new Vector3 ( hero.transform.position.x, hero.transform.position.y,hero.transform.position.z+20);
  49. //
  50. // StartCoroutine (doMoveToPoint (GameObject.FindGameObjectWithTag ("Respawn")));
  51. //
  52. // }
  53.  
  54.  
  55. private void move (Vector3 targetPoint)
  56. {
  57. if (!isFlying) {
  58. direction = new Vector3 (0, 0, 0);
  59.  
  60.  
  61. direction += targetPoint * Time.deltaTime;
  62.  
  63. }
  64.  
  65.  
  66. if (characterController.isGrounded && isFlying) {
  67. flyTempTime = 0;
  68. isFlying = false;
  69. }
  70.  
  71. if (!characterController.isGrounded) {
  72. flyTempSpeed -= flyTempTime / gravity;
  73. flyTempTime += Time.deltaTime;
  74. }
  75.  
  76.  
  77. direction.y = flyTempSpeed * Time.deltaTime;
  78. Vector3 ldirection = transform.TransformDirection (direction );
  79. characterController.Move (ldirection);
  80.  
  81. }
  82.  
  83.  
  84. public IEnumerator doMoveToPoint (GameObject targetObject)
  85. {
  86. JasioManager.Busy = true;
  87. animatio.run ();
  88. GameObject.FindGameObjectWithTag ("Model").transform.LookAt (targetObject.transform.position);
  89. //player.transform.LookAt (targetObject.transform.position);
  90. yield return StartCoroutine (MoveObject (player.transform, player.transform.position, targetObject.transform.position, 9.0f));
  91. animatio.rest ();
  92. JasioManager.Busy = false;
  93. print ("Statyczna" + JasioManager.Busy);
  94. }
  95.  
  96. IEnumerator MoveObject (Transform thisTransform, Vector3 startPos, Vector3 endPos, float time)
  97. {
  98. float i = 0.0f;
  99. float rate = 1.0f / time;
  100. while (i < 1.0f) {
  101. i += Time.deltaTime * rate;
  102.  
  103. if (Vector3.Distance (player.transform.position, endPos) < 2) {
  104. break;
  105. }
  106.  
  107. if (!isFlying) {
  108. direction = new Vector3 (0, 0, 0);
  109.  
  110.  
  111. direction += (endPos - startPos) * Time.deltaTime;
  112.  
  113. }
  114.  
  115.  
  116. if (characterController.isGrounded && isFlying) {
  117. flyTempTime = 0;
  118. isFlying = false;
  119. }
  120.  
  121. if (!characterController.isGrounded) {
  122. flyTempSpeed -= flyTempTime / gravity;
  123. flyTempTime += Time.deltaTime;
  124. }
  125.  
  126.  
  127. direction.y = flyTempSpeed * Time.deltaTime;
  128. Vector3 ldirection = transform.TransformDirection (direction);
  129. characterController.Move (ldirection);
  130.  
  131. //Time.timeScale = 0.1f;
  132. yield return null;
  133.  
  134. }
  135.  
  136. yield return null;
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement