Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!