Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
Stacking images in Unity

I have 4 buttons and each of this button activates an image (Please see the link - Stacking). One script is attached to all the 4 buttons. There are 4 placeholders. I am using an approach of stack to stack images one after another. That is, if the first slot is empty, the image goes there. The button has two functions, to add image and to remove image. If the first slot's image is removed, the second slot's image is placed on 1st slot and third slot's image is placed on 2nd slot. How do I add push and pop to this scenario?

Edit: I tried with List but I am lost. Could there be a way simpler approach?

public class ActivateStackImages : MonoBehaviour {

public GameObject ImageGameObject_To_Add; //Each instance of this script has unique image
public Vector3[] PositionOfImages; //4 positions
private ActivateStackImages [] activateImages; //Script added to 4 buttons

public bool Slot_1_Filled = false;
public bool Slot_2_Filled = false;
public bool Slot_3_Filled = false;
public bool Slot_4_Filled = false;

public bool isImageAdded = false;

    private void Awake () {
        activateImages= FindObjectsOfType (typeof (ActivateStackImages )) as ActivateStackImages [];

    }


    public void ActivateGraph () {

        if (this.isImageAdded == false) {
            for (int i = 0; i < activateImages.Length; i++) {

                if (activateImages[i].Slot_1_Filled == false) {
                    ImageGameObject_To_Add.SetActive (true);
                    ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[0];

                    activateImages[i].Slot_1_Filled = true;


                } else if (activateImages[i].Slot_2_Filled == false) {
                    ImageGameObject_To_Add.SetActive (true);
                    ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[2];

                    activateImages[i].Slot_2_Filled = true;


                } else if (activateImages[i].Slot_3_Filled == false) {
                    ImageGameObject_To_Add.SetActive (true);
                    ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[2];

                    activateImages[i].Slot_3_Filled = true;


                } else if (activateImages[i].Slot_4_Filled == false) {
                    ImageGameObject_To_Add.SetActive (true);
                    ImageGameObject_To_Add.GetComponent<RectTransform> ().anchoredPosition = PositionOfImages[3];

                    activateImages[i].Slot_4_Filled = true;


                }
            }

            this.isImageAdded = true;

  } else if (this.isImageAdded == true) {
            ImageGameObject_To_Add.SetActive (false);

  }
 }
}
  


Stacking

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda