Scripting a GameObject
Introduction
In this guide you will learn how to create a basic Lua script and add it to a game object.
What is a Lua Script?
- Lua is the scripting language used for creating dynamic and interactive Highrise Worlds.
- Learn more about Lua scripting.
❗️ When building a Highrise World, C# scripts are not included in the build. Make sure to use Lua scripts for your game objects.
Creating a Hello World Script
Let's create a simple script that prints "Hello, World!" to the console when the game starts.
Step 1: Create a Lua Script
- Open your project in Unity.
- In the Project panel, right-click and select Create > Highrise > Lua Script.
- Name the script
HelloWorldScript
and press Enter.
Step 2: Opening the Script
- Double-click the
HelloWorldScript
to open it in your code editor. - Write the following code in the script:
-- This script prints "Hello, World!" to the console
print("Hello, World!")
Learn more about coding fundamentals.
Step 3: Attaching the Script to a GameObject
- Right-click the
Hierarchy
panel. - Select 3D Object > Create Empty to create an empty game object.
- Rename the object to
HelloWorldObject
. - Pick the
HelloWorldObject
in theHierarchy
panel. - Drag the
HelloWorldScript
onto theHelloWorldObject
in theInspector
panel.
Step 4: Testing the Script
- Hit Play in Unity to enter Play Mode.
- Check the console for the "Hello, World!" message.
Conclusion
You have successfully created a Lua script that prints "Hello, World!" to the console when the game starts. This simple script demonstrates the basics of scripting in Highrise Studio. Experiment with different scripts to add interactivity and functionality to your game objects.
Video Preview
Next Steps
Delve deeper into lua scripting by learning about: