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

Use a button to transform a GameObject

Understand how you can transform a GameObject when you click on a button.
Read time 3 minutes
Last updated 2 months ago

Use this example to understand how to scale, rotate, or move a GameObject when the user clicks on a button.
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 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.
3

Add the script to the GameObject you want to transform

  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.
4

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 Clicked On event inside the When node. This triggers the logic when the user clicks the button.
  4. Select Add (+) next to Variables to create a new variable for the button and set its type to Object.
  5. Drag the
    button
    variable into the Clicked On socket.
  6. Add an action node to define how the GameObject should change when the user clicks the button. You can choose from:
    • ScaleByValue or ScaleToValue to change the size of the GameObject.
    • RotateByValue or RotateToValue to rotate the GameObject.
    • MoveByValue or MoveToValue to change the position of the GameObject.
  7. Drag the Me variable, which refers to the GameObject the script belongs to, into the Object socket.
  8. Enter the value you want to transform:
    • For scaling, enter the scale value. For example, if using a ScaleByValue node, a value of
      1
      doubles the object's size.
    • For rotation, enter the rotation angle.
    • For movement, enter the target position.
  9. Set the transformation time. Set it to
    0
    if you want the change to happen instantly.
Example Logic script to scale a GameObject when a button is clicked.

Example Logic script to scale a GameObject when a button is clicked.

  1. Close the Logic Editor.
5

Link the Button to your script

  1. In the Hierarchy panel, select the GameObject that has your Logic script attached.
  2. Drag the UI Button you created earlier from the Hierarchy panel into the button variable reference in your script component.
Press Play to test your scene. When you click the button, the GameObject transforms according to your specified logic.
Tip
Consider the following when you use action nodes:
  • byValue nodes apply a change relative to the current value. For example, increase scale by
    1
    .
  • toValue nodes set an absolute value. For example, set the scale value to
    2
    .
Some nodes will allow you to toggle LocalPosition. Enable to apply a transformation relative to the GameObject’s parent (its local space), not the whole scene (known as world space).

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