cwisbg

Untitled

Mar 13th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoPath : MonoBehaviour {
  6. private List<Vector3> PositionList = new List<Vector3>();
  7. public GameObject PositionListParent;
  8. private Vector3 CurrentPosition;
  9. private int PositionIndex = 0;
  10. public float MoPathSpeed = 1;
  11. private float PositionLerpAmnt;
  12. private Vector3 NewPosition;
  13. private Vector3 NewScale;
  14. private Vector3 StartScale;
  15. private Vector3 AimDirection;
  16. private int ListLen;
  17. public bool DoRandomize;
  18. void Start ()
  19. {
  20.  
  21. StartScale = transform.localScale;
  22. foreach (Transform child in PositionListParent.transform)
  23. {
  24. if (child.gameObject.activeSelf == true)
  25. {
  26. PositionList.Add(child.position);
  27. }
  28. //Debug.Log(child.position);
  29. }
  30. ListLen = PositionList.Count;
  31. CurrentPosition = transform.position;
  32. if (DoRandomize)
  33. {
  34. PositionIndex = Random.Range(0, ListLen - 1);
  35. }
  36. }
  37.  
  38. // Update is called once per frame
  39. void Update () {
  40.  
  41. NewPosition = Vector3.Lerp(CurrentPosition, PositionList[PositionIndex], PositionLerpAmnt);
  42.  
  43. if (PositionIndex == 1)
  44. {
  45. NewScale = Vector3.Slerp(Vector3.zero, StartScale, PositionLerpAmnt);
  46.  
  47. }
  48. if (PositionIndex == ListLen-1)
  49. {
  50. NewScale = Vector3.Slerp(StartScale, Vector3.zero, PositionLerpAmnt);
  51. }
  52.  
  53.  
  54. if (PositionLerpAmnt >= 1)
  55. {
  56. if (PositionIndex < ListLen)
  57. {
  58. CurrentPosition = transform.position;
  59. PositionIndex += 1;
  60. PositionLerpAmnt = 0;
  61. }
  62. if (PositionIndex == ListLen)
  63. {
  64. PositionIndex = 0;
  65. }
  66.  
  67.  
  68.  
  69. }
  70. //AimDirection = Vector3.RotateTowards(transform.position, PositionList[PositionIndex+1], 1, 360);
  71. if(PositionIndex < ListLen - 1)
  72. {
  73. transform.LookAt(PositionList[PositionIndex]);
  74. }
  75.  
  76. transform.localScale = NewScale;
  77. transform.position = NewPosition;
  78. PositionLerpAmnt += MoPathSpeed * Time.deltaTime;
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment