0 of 193 lessons complete (0%)
Exit Course
Scripting Part 3: Finishing the Game Loop

Change the VoxelObject Animation Frame

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

Now that we have a reference to the Voxel Object  component, we can set its animation frame. Just like when you reference a different entity, you will need to check that the voxel object is not null before you can do anything to it.

  1. In the onCollisionEnter function, in a new line after you created your voxelObject variable, write an if-statement to check that the voxel object is not null. 
  2. Inside the if-statement, call the showVoxelFrameAtKey(1) on voxelObject to set its animation to the second frame (the first frame is 0).

Note: Where is ‘!=null’?

You may have noticed that we just wrote if(voxelObject) instead of if(voxelObject != null). These actually work the same way, because null is what is called a falsy value. It isn’t the same thing as false, but if you use it in an if-statement, for example, it will get treated like false.

There are some other interesting falsy values, like NaN (Not a Number) or even -0. You can see a full list here.