A
A
ase20152019-04-15 10:57:28
Unity
ase2015, 2019-04-15 10:57:28

How can I make it so that when switching between pages in the game, the previous page closes?

There are 4 pages (there are 4 buttons on the panel) in the game, when you click on the first one, the first one opens, etc., but if you go from the first page to the second, then when you click on the second again (i.e. it closes), we transfers not to the menu, but to the first one because it is open, so how can I make the previous one close when I go to another page?
here is the code:

public GameObject business;
public GameObject reputation;
public GameObject building;
public GameObject VIP;
    

    

    public void building_ShowAndHide()
    {
        building.SetActive(!building.activeSelf);
    }

    public void rep_ShowAndHide()
    {
        reputation.SetActive(!reputation.activeSelf);
    }

    

    public void business_ShowAndHide()
    {
        business.SetActive(!business.activeSelf);
    }

    public void VIP_ShowAndHide()
    {
        VIP.SetActive(!VIP.activeSelf);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-04-15
@ase2015

To begin with, on the essence of the issue. (I won’t write ready-made code for you, but I’ll try to convey the essence for learning and understanding, it will be more useful)
You need to remember the page that you opened into a separate variable / link / flag.
And when opening any other - close / hide the current one, since we have a link and we know who exactly needs to be hidden / turned off / closed.
You just turn on and off each page on its own, without any connection with others.
And on the design of the question - this is not a difficult question, not even once.
And please make out the code with markup as code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question