Skip to content

Instantly share code, notes, and snippets.

@ghostofgamer
Last active October 1, 2023 06:32
Show Gist options
  • Select an option

  • Save ghostofgamer/9c3c38f3bb7007505fc772e66e4c2bd4 to your computer and use it in GitHub Desktop.

Select an option

Save ghostofgamer/9c3c38f3bb7007505fc772e66e4c2bd4 to your computer and use it in GitHub Desktop.

Revisions

  1. ghostofgamer revised this gist Oct 1, 2023. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions GoPlaces.cs
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    using System.Collections.Generic;
    using UnityEngine;

    public class Place : MonoBehaviour
    public class Movement : MonoBehaviour
    {
    private float _speed;
    private int _index;
    @@ -29,18 +29,17 @@ private void Update()
    }
    }

    private Vector3 GetNextPlace()
    {
    var pointVector = _arrayPlaces[_index].transform.position;
    transform.forward = pointVector - transform.position;
    return pointVector;
    }

    private void GetNextIndex()
    {
    _index++;

    if (_index == _arrayPlaces.Length)
    _index = 0;
    }

    private void GetNextPlace()
    {
    var pointVector = _arrayPlaces[_index].transform.position;
    transform.forward = pointVector - transform.position;
    }
    }
  2. ghostofgamer revised this gist Sep 30, 2023. 1 changed file with 22 additions and 12 deletions.
    34 changes: 22 additions & 12 deletions GoPlaces.cs
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,46 @@
    public class GoPlaces : MonoBehaviour
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Place : MonoBehaviour
    {
    private float _speed;
    private int _index;
    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>();
    _arrayPlaces[i] = _allPlacesPoint.GetChild(i);
    }

    private void Update()
    {
    var pointInArray = _arrayPlaces[_indexPlaces];
    var pointInArray = _arrayPlaces[_index];
    transform.position = Vector3.MoveTowards(transform.position, pointInArray.position, _speed * Time.deltaTime);

    if (transform.position == pointInArray.position)
    NextPlaceTakerLogic();
    {
    GetNextIndex();
    GetNextPlace();
    }
    }

    public Vector3 NextPlaceTakerLogic()
    private Vector3 GetNextPlace()
    {
    _indexPlaces++;

    if (_indexPlaces == _arrayPlaces.Length)
    _indexPlaces = 0;

    var pointVector = _arrayPlaces[_indexPlaces].transform.position;
    var pointVector = _arrayPlaces[_index].transform.position;
    transform.forward = pointVector - transform.position;
    return pointVector;
    }

    private void GetNextIndex()
    {
    _index++;

    if (_index == _arrayPlaces.Length)
    _index = 0;
    }
    }
  3. ghostofgamer created this gist Sep 27, 2023.
    36 changes: 36 additions & 0 deletions GoPlaces.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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;
    }
    }