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.
- In the ChestScript, at the bottom, create a new function called reset.
- 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.
- Set the hasBeenDug variable back to false.
- Create a variable a reference to the chestLid from the chestLidRef variable using get.
- Create an if-statement that checks if the chestLid is not null.
- Inside the if-statement, send an event to the chestLid to “startLidAnimation”, with a second input of “close” to close the lid.