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

Enable or disable a property on a GameObject

Learn how to use a Logic script to enable or disable properties on a GameObject.
Read time 2 minutes
Last updated 2 months ago

This example shows you how to set up a script that enables or disables the gravity of a GameObject. You can also use these steps to alter different properties.
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.
  2. Select the cube. The Inspector window for that cube opens.
  3. Within the Physics component, disable Use Gravity.
3

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. To rename your script, right click the script and select Rename. Make sure the name doesn't contain spaces.
4

Add the script to the Cube

  1. Select the Cube from the Hierarchy panel.
  2. From the Inspector window, 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. Create the following variables:
  • Unique name :
    Cube_Rigidbody
    , Type :
    Rigidbody
  • Unique name :
    Button
    , Type :
    Object
  1. Set up the following logic to enable the gravity when the user clicks the button:
  • Drag a When event listener into the Logic Editor.
  • Place a Clicked on node in the When node's Event socket.
  • Drag the
    Button
    variable in the Clicked on node.
  • Drag a Set variable value action into the When node.
  • In the variables, expand the
    Cube_Rigidbody
    properties. Drag the useGravity property to the first socket of the Set variable value node. Set its value to
    True
    .
Example Logic script to set the cube to be non-interactive.

Example Logic script to enable or disable a property of a GameObject.

6

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_Rigidbody
    variable references in your script component.
  3. Drag the button from the Hierarchy panel into the
    Button
    variable reference in your script component.
  4. Press Play to test your scene. When you click on the button, it activates gravity on the cube.
Tip
Follow the same steps to enable or disable a collider:
  • Change the variable type from
    Rigidbody
    to
    Collider
    .
  • Expand the
    Collider
    properties and use the
    enabled
    property.

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