The template imported in the last lesson had Lua scripts included. This lesson will be creating a sample script to see how this code works and will be useful in the future.
The scripts imported can be seen in the Project Content window. There are three scripts to operate the doors and one script to toggle a VFX for the Treasure object in the 2nd puzzle room.
The Start Door is a basic door found in the Core Content window. It will open and close based on the player’s proximity to the door. This uses the BasicDoorControllerServer and BasicDoorControllerClient scripts.
There are three Puzzle Doors for each room. They are a modified version of the default door that will only open when a specific server event is broadcasted. This will be useful to only open the door once the player has solved the riddle. It uses the PuzzleDoorControllerServer script.
The PlaySparkle script can receive two client events to enable and disable a Sparkle effect on the Treasure object in the second puzzle room. This will be useful for the second puzzle that requires the player to know if it is looking at the Treasure directly.
Create a New Script
In the Hierarchy window, create a new folder named Scripts. Create a Server Context inside the Scripts folder. Create a new script named ImportedScriptsTest and place it in the Server Context.
Add a Custom Property
Select the ImportedScriptsTest and open the Properties window. At the bottom, click the Add Custom Property button. Select the Bool type and name it RunTest. This will be used to indicate whether or not we want the script to run. Click the checkbox next to the RunTest property to activate it.
Open the Puzzle Doors
Add the following code to the ImportedScriptsTest script.
When broadcasting the OpenPuzzleDoor event, it requires a second parameter of a string to control which door is being opened. This string is being compared to an id custom property on each of the Puzzle Door objects.
Preview the Project
Press the Play button and check if the doors open in the correct order and the Treasure Sparkle effect plays.
Now that the imported code functionality is clear, deactivate the custom property RunTest on the script.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!