Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Walk : MonoBehaviour {
  6.  
  7. public GameObject[] Waypoints;
  8. public int currTarget = 0;
  9. public int waypointLength;
  10. public float speed = 3;
  11. public float changeTargetValue = 1;
  12. public float rotationSpeed = 9;
  13.  
  14. public float time= 0;
  15.  
  16. void Start ()
  17. {
  18. waypointLength = Waypoints.Length;
  19.  
  20. }
  21.  
  22.  
  23. void Update ()
  24. {
  25. time += Time.deltaTime;
  26.  
  27. if (time > 0.5f)
  28. {
  29. if (currTarget < waypointLength)
  30. {
  31.  
  32. var lookPos = Waypoints[currTarget].transform.position - transform.position;
  33. lookPos.y = 0;
  34. var rotation = Quaternion.LookRotation(lookPos);
  35.  
  36. transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);
  37.  
  38. transform.Translate(Vector3.forward * Time.deltaTime * speed);
  39.  
  40.  
  41. if (Vector3.Distance(transform.position, Waypoints[currTarget].transform.position) < changeTargetValue)
  42. {
  43. currTarget++;
  44. }
  45.  
  46. }
  47.  
  48. }
  49.  
  50.  
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement