Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 1: Moving Objects

Use a Variable

You don’t have access to this lesson

Please register or sign in to access the course content.

You may have noticed the variable someNumber above the start function in your code. We can make one for the amount we want the chest to move up so that it’s easy to change and adjust later.

  1. Change the name of the variable, someNumber, to amountToMoveUp.
  2. Change the value of the variable from 42 to 10.
  3. In the start function, change the amount you add to the chest’s y position from 10  to this.amountToMoveUp.

Note: Why ‘this’ this time? 

When you make a variable above the start function, it becomes a property of the script, so you need to write this. to find it. We’ll look at ways to make variables that don’t need a this later in the lesson.