Documentation

Support

Unity Lite

Open Unity Lite

Unity Lite

Hide or show a UI element

Understand how you can hide or show a UI element after a set time delay.
Read time 1 minuteLast updated 2 days ago

Use this example to understand how to hide or show a UI element after a set time delay.
1

Create a button in your UI Canvas.

  1. Select UI Canvas in the Hierarchy panel.
  2. Right-click and choose UI > Button to create a new button.
2

Hide the button by default.

  1. Select the button in the Hierarchy panel.
  2. In the Inspector panel, uncheck the checkbox next to the button's name to hide the button by default.
3

Create a New Logic script.

  1. In the Project panel, select the My Logic folder.
  2. Select Add (+).
  3. Select New Script. Unity Lite creates a new Logic script in the folder.
  4. Enter a name for your script and press Enter.
4

Add the script to a GameObject in your scene.

  1. Select or create a GameObject from the Hierarchy panel.
  2. From the Inspector panel, select Add Component.
  3. Choose your Logic script from the list.
5

Set up the logic in the Logic Editor.

  1. In the Project panel, double-click the Logic script to open the Logic Editor.
  2. Drag a When event listener into the Logic Editor.
  3. Add a Play Starts event inside the When node. This triggers the logic when the application starts.
  4. Drag a Wait node inside the When node.
  5. Set the Wait value to
    3
    seconds. This adds a delay.
  6. Create a new variable for the Button, and set its type to Object.
  7. Expand the button variable properties and methods.
  8. Drag the Set Active method into your logic chain, and set it to true.
Example Logic script to show a UI element after a delay.

Example Logic script to show a UI element after a delay.

  1. Close the Logic Editor.
6

Connect your Button reference.

  1. In the Hierarchy panel, select the GameObject that has your Logic script attached.
  2. Drag your button from the Hierarchy into the Button variable reference in your script component.
Press Play to test your scene.

Hide or show a UI element • Unity Lite • Unity Docs