Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 3: Finishing the Game Loop

Stop the Chest Animation from Repeating

You don’t have access to this lesson
Please register or sign in to access the course content.

Right now, the chest animation will happen every single time you walk into the trigger. You can go ahead and test this, interrupting the animation and making it restart every time you. To fix it, we’ll create another variable that we set to true the first time the animation is finished, and only start the animation if it is false.

  1. In the ChestLidScript, create a variable above the start function named hasBeenDug and set it to false.
  2. In the moveChest function, find the else that happens once after the animation finishes, and set the hasBeenDug variable to true
  3. In the first line of the startDiggingUpChest animation, use an if-statement to check if hasBeenDug is true, and if so, use return to cancel the rest of the function.