Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 1: Moving Objects

Make Variables Private

You don’t have access to this lesson

Please register or sign in to access the course content.

If we look at the entity panel, there are now 5 variables there, Amount To Move Up, Should Chest Move, Animation Time, Elapsed Time, and Starting Position. Some of these are really useful to have there, because it means you can make adjustments to how your game works without having to change the script, or have different copies of the same script produce slightly different animations.

Others, however, either won’t do anything if you change them, or will even break your code:

  • startingPosition gets changed as soon as the code runs to wherever the chest was when the animation started. You could write any number you wanted in the entity panel, and it would not matter, because it gets changed immediately.
  • elapsedTime has to be 0. If you change it to anything else, it will change how your animation works.

To fix the potential problems here, we can make these variables private. Making a variable private is how you show in a program that the code will change it, but we humans should not. In dotbigbang, it also takes it off of the Entity panel.

  1. Right before the lines where you declare the startingPosition and elapsedTime variables, add the keyword private.
  2. Save your script, and check the Entity panel to make sure that these variables are no longer there.