Documentation

​
​

Development

User Acquisition

Monetization

Industry

Unity Studio

Open Unity Studio

Unity Studio

​
​
Unity Studio
  • What's new in Unity Studio
  • Introduction to Unity Studio
  • Launch Unity Studio
  • Create your first Unity Studio project
  • Develop with Unity Studio
    • The Unity Studio interface
    • Save your progress
    • GameObjects
    • Assets
    • Materials
    • Scene settings
    • Logic
      • Introduction to Logic
      • Create a Logic script
      • The Logic Editor interface
      • Methods, variables, and parameters
      • Nodes
      • Logic examples
        • Use a button to transform a GameObject
        • Hide or show a User Interface (UI) element
        • Trigger an animation on key press
        • Adjust scene lighting with a button
        • Interact with an asset after an event
        • Display the name of a GameObject on hover
        • Enable or disable a property on a GameObject
        • Play audio when you click an object
        • Mute and unmute audio with the toggle element
        • Use sliders to change a material's color
    • The UI Creator
    • Animation
    • AI features
  • Collaborate in Unity Studio
  • Export drafts to the Unity Editor
  • Publish and share
  • Troubleshooting Unity Studio issues
  • Report bugs and share feedback
  • Manage your analytics and marketing preferences
  1. Unity Studio
  2. Develop with Unity Studio
  3. Logic
  4. Logic examples

Interact with an asset after an event

Learn how to interact with a GameObject based on a specific event, such as a button click.
Read time 3 minutes
Last updated 2 months ago

Use this example to learn how to interact with a GameObject based on a specific event, such as a button click.
1

Create a button in your UI Canvas

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

Create a Cube in your scene

  1. Right-click in the Hierarchy panel and select Primitives > Cube to create a new Cube GameObject.
3

Create an Animation

  1. Select the Cube in the Hierarchy panel.
  2. Add an Animation component to your Cube from the Inspector.
  3. Create your animation and give it a name. For more information, refer to Animate a GameObject with the Animation component.
4

Create a New Logic script

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

Add the script to the Cube

  1. Select the Cube from the Hierarchy panel.
  2. From the Inspector panel, select Add Component.
  3. Choose your Logic script from the list.
6

Set up the logic in the Logic Editor

  1. In the Project panel, double-click the Logic script to open the Logic Editor.
  2. Create the following variables:
    • Cube
      with an Object type.
    • Cube_Interactive
      with a Bool type.
    • Cube_Animation
      with an Animation type.
    • Button
      with an Object type.
  3. Set the cube to be non-interactive at the start.
    • Drag a When event listener into the Logic Editor.
    • Place a Play Starts node in the socket. This triggers the logic when the application starts.
    • Drag a Set variable value action into the When node.
    • In the first socket, add your Cube_Interactive Bool variable.
    • Set its value to false.
    Example Logic script to set the cube to be non-interactive.

    Example Logic script to set the cube to be non-interactive.

  4. Enable interactivity When Button is Clicked:
    • Drag a When event listener into the Logic Editor.
    • Place a Clicked On event in the socket.
    • Add your Button variable in the Clicked On socket.
    • Drag a Set variable value action into the When node.
    • In the first socket, add your Cube_Interactive Bool variable.
    • Set its value to true.
    Example Logic script to enable interactivity when a button is clicked.

    Example Logic script to enable interactivity when a button is clicked.

  5. Trigger the Cube's animation:
    • Drag a When event listener into the Logic Editor.
    • Place a Clicked On event in the socket.
    • Add your Cube variable in the Clicked On socket.
    • Drag an If Else flow control node inside the When event listener.
    • Drag an Equal operator node into the If socket,
    • In the first socket of Equal, add your Cube_Interactive Bool variable.
    • Set second socket of Equal to true.
    • Inside the If branch, drag a Play Animation action.
    • Type the animation name in the first socket.
    • Drag the Cube_Animation variable into the second socket.
    • Inside the Else branch, drag a Return node and leave it empty.
    • Close the Logic Editor.
Example Logic script to trigger an animation.

Example Logic script to trigger an animation.

7

Connect your script references

  1. In the Hierarchy panel, select the GameObject that has your Logic script attached.
  2. Drag the Cube from the Hierarchy panel into the Cube and Cube_Animation variable references in your script component.
  3. Drag the Button from the Hierarchy panel into the Button variable reference in your script component.
Press Play to test your scene. The Cube becomes interactive when you click the button.
Tip
Use this approach for any GameObject or UI element when you want to control the exact moment it becomes interactive.

Additional resources

  • Introduction to Logic
  • The Logic Editor interface
  • Create a Logic script
  • Methods and variables
  • Nodes
  • Logic examples

Copyright © 2026 Unity Technologies
LegalPrivacy PolicyCookiesDocumentation Terms of UseDo Not Sell or Share My Personal InformationYour Privacy Choices (Cookie Settings)

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S and elsewhere (more info here). Other names or brands are trademarks of their respective owners.

Some pages are machine-translated for convenience, and may contain inaccuracies. In the event of conflicting information, the English version is authoritative.

  • On this page
    • Additional resources


Report a problem with this page