2
I’m using unity3D, so my queue consists of Gameobjects, are 7 Gameobjects lined up next to each other and my purpose with this code is that every click of the user - "Simplemove function" - the objects move forward one position, except the last one, this must take the last position.
In Unity it is possible to associate the Gameobjects by the interface, so consider the two full arrays already at the beginning.
I would like help to understand and develop the logic in "Simplemove function" make this drive. Thank you
using UnityEngine;
using System.Collections;
public class StairsController : MonoBehaviour {
public GameObject[] degrau;
Vector3[] positionArray = new Vector3[7];
private int i = 6;
private int a = 6;
// Use this for initialization
void Start () {
positionArray [i-6] = degrau[a-6].transform.position;
Debug.Log (positionArray [i-6]);
positionArray [i-5] = degrau[a-5].transform.position;
Debug.Log (positionArray [i-5]);
positionArray [i-4] = degrau[a-4].transform.position;
Debug.Log (positionArray [i-4]);
positionArray [i-3] = degrau[a-3].transform.position;
Debug.Log (positionArray [i-3]);
positionArray [i-2] = degrau[a-2].transform.position;
Debug.Log (positionArray [i-2]);
positionArray [i-1] = degrau[a-1].transform.position;
Debug.Log (positionArray [i-1]);
positionArray [i] = degrau[a].transform.position;
Debug.Log (positionArray [i]);
}
public void SimpleMov (){
degrau [a].transform.position = positionArray [i - 1];
}
}
How can I move objects between the positions of this list?
– Vitor Figueredo
You said you have elements in sequence, 1,2,3,4 You want them to move forward and the latter hold the last position. 2,3,4. Just remove the first one. If you want to swap objects, there are several functions in the link I sent at the end, various types of Sort. And if you want you can do a function as it is here: http://stackoverflow.com/questions/2094239/swap-two-items-in-listt
– Nils
If you want the FIRST to take the last position, as in an escalator you can try to use Queue (first in, first out). https://msdn.microsoft.com/en-us/library/7977ey2c(v=vs.100). aspx
– Nils
In this case, if you want to keep the size fixed, you can use array, then just put an index to tell where the "start of the queue".
– Nils
Yeah, I talked to a guy at Stack Overflow in English to discuss this problem and it seemed a lot more complicated than initially, we solved it using two of the guys who went through the list and always started from a forward position, but also zeroed out when they found the last element.
– Vitor Figueredo
Strange, it seems to me very simple the solution. Is there any information that you passed on to him and did not pass it on to us? Or did you pass it on differently?
– Nils