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
        • Introduction to variables, methods and parameters
        • Create a variable
        • New Variable window reference
        • Create a method
        • New Method window UI reference
      • Nodes
      • Logic examples
    • 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. Methods, variables and parameters

Introduction to variables, methods, and parameters

Use methods, variables, and parameters to store data, perform actions, and control the flow of your Logic scripts.
Read time 3 minutes
Last updated 2 months ago

Variables

A variable is a container you can use to store information like numbers, text, colors, or references to objects to use in your Logic scripts.
For example:
  • You operate a solar-plus-battery site.
  • You create a variable named
    BatteryStateOfCharge
    to store the battery’s current charge level.
  • BatteryStateOfCharge
    is a number that changes as the battery charges and discharges.
  • You make
    BatteryStateOfCharge
    a
    float
    type to hold decimal values for precise control.
  • When sensors report a new reading, you update
    BatteryStateOfCharge
    . If it drops below a threshold, your Logic triggers an alert.
For instructions on how to create a variable, refer to Create a variable.

Methods

Use methods to group a set of actions together that perform a specific task. Methods can also help keep your Logic scripts modular and organized.
For example:
  • You have a door in your scene that you want to open when the user clicks on it.
  • You create a method called
    OpenDoor
    that contains the logic to open the door:
    • Animate the door object as it opens.
    • Play a creaking sound.
  • Then, whenever you want to open the door in your logic, you just call the
    OpenDoor
    method instead of rewriting the same logic over and over again.
For instructions on how to create a method, refer to Create a method.

Return values

A method can return a value after it runs. This is useful when you want to get some information back from the method.
For example, with the
OpenDoor
example, you might want to know when the door finishes opening. You can modify the method to return a true/false value, which returns
true
when the door is open.
In this case, the return type of the method is a Bool value. However, if you don't want to return any value, you can set the return type to Void. The method performs the action but doesn't return anything.
For more information about return types, refer to New Method window reference.

Use methods in your logic

If you create a method with a return type other than Void, you can drag the method node from the right panel into the Logic Editor.
Note
Select the node to swap its type between expression (round node, returns a value), and statement (square node, executes, and ignores the returned value). This lets you use the method in different ways depending on your Logic script's needs.

Parameters

A parameter is a variable that you pass into a method when you use it. Parameters let you reuse the same method but with different inputs each time.
For example:
  • You want to create a notification that shows the user different messages.
  • You create a method called
    ShowNotification
    and give it a parameter called
    Message
    of type
    String
    .
  • You give the method the following logic:
    • Display the
      Message
      text on the screen.
    • Animate the UI element to slide in and out.
    • Play a notification sound.
  • Now, whenever you want to show a notification, you call the
    ShowNotification
    method and pass in the message you want to display:
    • You have a new message.
    • An error occurred.
This way, you can use the same method to show different messages without rewriting the logic each time.
You can create parameters when you create a method. For information about parameter properties, refer to Parameter details.

Additional resources

  • Create a variable
  • Create a method
  • New Method window reference

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
    • Variables

    • Methods

      • Return values

      • Use methods in your logic

    • Parameters

    • Additional resources


Report a problem with this page