Search code examples
pythonursina

my on click function is not working in ursina


I don't know how to do that when the user clicks on Settings so that everything is invisible. I tried

Play.on_click = Settings.visible = False
Play.on_click = quit.visible = False
Play.on_click = Play.visible = False

but it doesn't work


Solution

  • on_click expects a function but you assigned a value. Try this instead:

    def play_onclick():
        Settings.visible = False
        quit.visible = False
        Play.visible = False
    
    Play.on_click = play_onclick # without parentheses! 
    

    Also, I'm assuming that Play is a ursina.Button instance. If that's the case, you should follow the Python naming convention of having its name start with a lowercase letter, i.e. play.