H
H
Hixac2020-10-05 19:38:44
Unity
Hixac, 2020-10-05 19:38:44

Why does the tail list not respond to movement, but the first element in the list does?

I don't have any errors. But when the first part of the tail "grows", i.e. the first element is supposed to work fine, but the rest don't.

public class TailAdder : MonoBehaviour
 {
     [SerializeField] private GameObject tailPrefab;
     private GameObject _tail;
     public int numerate;
     public int nomerrate;
     private float ourTimer;
     List<GameObject> _tails = new List<GameObject>();
     Move move = null;
     void Start()
     {
         move = GetComponent<Move>();
     }
 
     void Update()
     {
         ourTimer += Time.deltaTime;
         if (numerate == 1)
         {
             _tail = Instantiate(tailPrefab) as GameObject;
             _tail.name = "tail" + nomerrate;
             _tails.Add(_tail);
             nomerrate++;   
             numerate = 0;            
         }
         if (nomerrate >= 1)
         {
             for (int i = 0; i < nomerrate; i++)
             {
                 _tail = _tails[i];
                 if (ourTimer >= 0.25f)
                 {
                     _tail.transform.position = move.previouslyPos;
                     _tail.transform.rotation = move.rotationPoint;
                     ourTimer = 0f;
                 }
             }
         }
     }
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hixac, 2020-11-18
@Hixac

How to Create a Snake Tail
Using Linq

if (tailsList.Count >= 1)
        {
            tailsList.Last().transform.position = lastPos;
            tailsList.Last().transform.rotation = lastRot;
            tailsList.Insert(0, tailsList.Last());
            tailsList.RemoveAt(tailsList.Count - 1);
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question