I am creating a queue, and I can not develop the function logic so that the previous object assumes the new released position - C #

2

I'm using unity3D, so my queue is made up of GameObjects, there are 7 GameObjects queued next to each other and my purpose with this code is that with every click of the user - " SimpleMove Function "- the objects move forward, except the last one, it must assume the last position.

In Unity it is possible to associate GameObjects with the interface, so consider the two arrays already full at the beginning.

I would like help in understanding and developing the logic in the "SimpleMove Function" that makes this move. Thanks

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];
    }
}
    
asked by anonymous 10.07.2015 / 21:48

1 answer

1

Great tip: only use array for single-sized structures that do not need modification, for variable sizes and other firulas use "List" is much easier and you will have great processing savings.

You will need

using System.Collections.Generic;

To start

List<GameObject> degrau= new List<GameObject>();

To add elements

degrau.Add(**teu degrau aqui**);

To remove the element has several options, but this should be the most appropriate.

degrau.RemoveAt(int index)

and

degrau.Clear()

to clean

  

More information about the list    link

I do not have a specific video to list, but I use it in this video here link

    
11.07.2015 / 02:01