Linear Translation

Unity3D 2015. 8. 27. 20:11
반응형
  1. http://answers.unity3d.com/questions/339561/linear-translation.html
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. public class FollowPath : MonoBehaviour {
  6. public GameObject follower;
  7. public Transform[] pathNodes;
  8. public float movementSpeed = 0.5f;
  9. public bool continuouslyLoop = false;
  10. private float pathPosition = 0f;
  11. private int curNode = 0;
  12. // Use this for initialization
  13. void Start () {
  14. if (follower == null) {
  15. follower = this.gameObject;
  16. }
  17. }
  18. // Update is called once per frame
  19. void Update () {
  20. if (pathNodes != null)
  21. {
  22. pathPosition += Time.deltaTime * movementSpeed;
  23. if (pathPosition > 1f)
  24. {
  25. if (pathNodes.Length > curNode+2)
  26. {
  27. pathPosition = 0f;
  28. curNode += 1;
  29. }
  30. else
  31. {
  32. if (continuouslyLoop)
  33. {
  34. pathPosition = 0f;
  35. curNode = 0;
  36. }
  37. }
  38. }
  39. follower.transform.position = Vector3.Lerp( pathNodes[curNode].position, pathNodes[curNode+1].position, pathPosition );
  40. }
  41. }
  42. }


반응형

'Unity3D' 카테고리의 다른 글

Text 한글자씩 나오게 하는 방법.  (0) 2015.08.31
NGUI position to World position  (0) 2015.08.27
타일맵 생성 ( isometric )  (0) 2015.08.26
astar_test 5  (0) 2015.08.24
astar test 4  (0) 2015.08.24
: