Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 2: Making Code Respond to Players

Keep the Animation from Starting Automatically

You don’t have access to this lesson

Please register or sign in to access the course content.

Right now the chest lid animation starts as soon as the game loads, which is great for testing, but not the way we want it to work in the end. To fix this, we just need an if-statement and a boolean variable to keep it from going right away.

  1. Above the start function, create a variable called startAnimation and set it to false.
  2. In the beginning of the tick function, create a new if-statement whose condition is the value of this.startAnimation
  3. Move the final } curly bracket to go after all the code in the tick function.
  4. Indent all that code so that it is clear  

Tip: Tab and Shift+Tab

Unlike your normal word editing program, in the script editor, you can select several lines, and press Tab to indent them all one level at once. You can also use Shift+Tab to move the indentation back to the left.