Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 3: Finishing the Game Loop

Make a Reset Function on the Chest Script

You don’t have access to this lesson

Please register or sign in to access the course content.

Our next challenge is to make it possible to restart the whole game without having to press Stop and Play in Edit mode. The first step will be to make a function for the chest to reset itself.

  1. In the ChestScript, at the bottom, create a new function called reset.
  2. Put the chest well below the world so that it can’t be seen, by setting the y value of its worldTransform position to a large negative number, like -100
  3. Set the hasBeenDug variable back to false.
  4. Create a variable a reference to the chestLid from the chestLidRef variable using get.
  5. Create an if-statement that checks if the chestLid is not null
  6. Inside the if-statement, send an event to the chestLid to “startLidAnimation”, with a second input of “close” to close the lid.