Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

61
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

9 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.