Last active
October 1, 2023 06:32
-
-
Save ghostofgamer/9c3c38f3bb7007505fc772e66e4c2bd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class GoPlaces : MonoBehaviour | |
| { | |
| private float _speed; | |
| private Transform _allPlacesPoint; | |
| private Transform[] _arrayPlaces; | |
| private int _indexPlaces; | |
| private void Start() | |
| { | |
| _arrayPlaces = new Transform[_allPlacesPoint.childCount]; | |
| for (int i = 0; i < _allPlacesPoint.childCount; i++) | |
| _arrayPlaces[i] = _allPlacesPoint.GetChild(i).GetComponent<Transform>(); | |
| } | |
| private void Update() | |
| { | |
| var pointInArray = _arrayPlaces[_indexPlaces]; | |
| transform.position = Vector3.MoveTowards(transform.position, pointInArray.position, _speed * Time.deltaTime); | |
| if (transform.position == pointInArray.position) | |
| NextPlaceTakerLogic(); | |
| } | |
| public Vector3 NextPlaceTakerLogic() | |
| { | |
| _indexPlaces++; | |
| if (_indexPlaces == _arrayPlaces.Length) | |
| _indexPlaces = 0; | |
| var pointVector = _arrayPlaces[_indexPlaces].transform.position; | |
| transform.forward = pointVector - transform.position; | |
| return pointVector; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment