Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Buttons

Discussion in 'Scripting' started by unity_TR7C4xry9zxIAw, Jan 7, 2021.

  1. unity_TR7C4xry9zxIAw

    unity_TR7C4xry9zxIAw

    Joined:
    Jul 8, 2020
    Posts:
    26
    Hello,

    I'm showing objects visible when I click the button. However, if you click the button again to release it, the object is still visible. I want the object to be invisible when I release the button.
    I use this below one(Interactable-Events), but I think i use scripts. Could you give some tips?
     

    Attached Files:

  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    Two main ways to do this:

    1. Write your own function in script that checks the current state of the object and then sets it to the opposite of that. Make your button call that function.

    2. Make 2 buttons in the same place on the screen. The first button shows your object, hides itself, and shows the second button. The second button hides your object, hides itself, and shows the first button.
     
  3. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    Do you mean you want the object to appear on mouse down, then disappear on mouse up? "Click" means down AND up, and is only fired when the button is released. If you want the button to be a trigger (appear on down, disappear on up), add Events: OnPointerDown, OnPointerUp.
     
    EdGunther likes this.
  4. EdGunther

    EdGunther

    Joined:
    Jun 25, 2018
    Posts:
    183
    OnMouseDown = set active
    OnMouseUp = set inactive
     
  5. unity_TR7C4xry9zxIAw

    unity_TR7C4xry9zxIAw

    Joined:
    Jul 8, 2020
    Posts:
    26
    What you mean is that I have to press the button to see the object?
     
  6. EdGunther

    EdGunther

    Joined:
    Jun 25, 2018
    Posts:
    183
    What do you want to happen when you click the button?