Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17063

Unity - Observer pattern or conditional logic in Update method for controlling UX visibility

$
0
0

So i have a bit of a conundrum at the moment. I have a piece of UX (in a Canvas panel) that needs to be shown or hidden, depending on some condition in gameplay logic. Up until now I've been doing this with conditional logic in the Update method of a MonoBehaviour, i.e. something like this:

public GameObject uxPanel;
 
void Update()
{
    if (uxShowCondition)
    {
        uxPanel.gameObject.SetActive(true);
    }
    else
    {
        uxPanel.gameObject.SetActive(false);
    }
}

 

Simple and it works. The problem is that this conditional logic gets called every single frame. I know Unity is optimized for running these Update …


Viewing all articles
Browse latest Browse all 17063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>