Creating and Using Scripts

The GameObject behaviors are controlled by the component mounted on it. We can add the Para Script Component to an object and associate it with a custom script in order to add custom behavior logic.

1. Create custom script files

On the [Project] panel, select the [+] menu on the upper left, or right-click on the blank area on the [Project] panel to open the create menu. Select ParaSpace → LuaScript.
You may also select Assets → Create → ParaSpace → Lua Script.

621

ParaSpace → LuaScript

After that, you will generate a Lua Script file under the currently selected folder, as shown below.

861

Lua Script successfully generated

2. Associate the script file with GameObject

Select a GameObject, and use the following way to add the ParaScript component under the [Inspector] panel.
Click [Add Component], then select ParaSpace → Para Script.

907

Select ParaSpace → Para Script

907

Successfully added the Para Script component

After that, drag the newly generated Lua Script to Script Asset to complete the association. As shown below.

907

Associate with Lua Script file

You may also choose to drag the newly generated Lua Script file to the corresponding GameObject's [Inspector] panel to quickly create components and associate!

3. Edit script content

Double-click the file to open it for editing with the Unity development tools.
The newly generated Lua Script code is as follows.

-- Start is called before the first frame update
function Start()
    
end

For demonstration purposes, let us add the print code to the Start method and print out some logs.

-- Start is called before the first frame update
function Start()
    print("Hello World")
end

4. View running result

World Debugger needs to be configured in order for you to view the running result of the script. For more details, please refer to the following: How to Debug

After running successfully, you can view the outputted log on the [console] panel.

781

Run successfully, display log

🚧

Unable to debug the world directly through clicking the Unity Play button

Lua Script runs in a specific environment, please follow the guide to configure the World Debugger properly before you start to debug.
Clicking the Play button directly doesn't allow you to view the running effect.