Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MoPath : MonoBehaviour {
- private List<Vector3> PositionList = new List<Vector3>();
- public GameObject PositionListParent;
- private Vector3 CurrentPosition;
- private int PositionIndex = 0;
- public float MoPathSpeed = 1;
- private float PositionLerpAmnt;
- private Vector3 NewPosition;
- private Vector3 NewScale;
- private Vector3 StartScale;
- private Vector3 AimDirection;
- private int ListLen;
- public bool DoRandomize;
- void Start ()
- {
- StartScale = transform.localScale;
- foreach (Transform child in PositionListParent.transform)
- {
- if (child.gameObject.activeSelf == true)
- {
- PositionList.Add(child.position);
- }
- //Debug.Log(child.position);
- }
- ListLen = PositionList.Count;
- CurrentPosition = transform.position;
- if (DoRandomize)
- {
- PositionIndex = Random.Range(0, ListLen - 1);
- }
- }
- // Update is called once per frame
- void Update () {
- NewPosition = Vector3.Lerp(CurrentPosition, PositionList[PositionIndex], PositionLerpAmnt);
- if (PositionIndex == 1)
- {
- NewScale = Vector3.Slerp(Vector3.zero, StartScale, PositionLerpAmnt);
- }
- if (PositionIndex == ListLen-1)
- {
- NewScale = Vector3.Slerp(StartScale, Vector3.zero, PositionLerpAmnt);
- }
- if (PositionLerpAmnt >= 1)
- {
- if (PositionIndex < ListLen)
- {
- CurrentPosition = transform.position;
- PositionIndex += 1;
- PositionLerpAmnt = 0;
- }
- if (PositionIndex == ListLen)
- {
- PositionIndex = 0;
- }
- }
- //AimDirection = Vector3.RotateTowards(transform.position, PositionList[PositionIndex+1], 1, 360);
- if(PositionIndex < ListLen - 1)
- {
- transform.LookAt(PositionList[PositionIndex]);
- }
- transform.localScale = NewScale;
- transform.position = NewPosition;
- PositionLerpAmnt += MoPathSpeed * Time.deltaTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment