Moving platforms
Now let's refine the adventure further by adding a moving element to the existing scene; specifically, a moving platform object. This platform should move up and then down again on a loop, ping-ponging between extremes. The player will be able to jump onto the platform to hitch a ride, and the object will be constructed as a prefab, allowing it to be reused across scenes. See Figure 6.1 for the result:
To start, select the platform texture in the Project panel, making sure that it's specified as a Sprite (2D and UI) texture type in the Object Inspector. The Sprite Mode should be set to Single. Drag and drop the platform texture to the scene and set its Scale to (0.7
, 0.5
, 1
). See Figure 6.2:
Next, the platform should be a solid object, the kind of thing with which the player can collide. Remember, the player should be able to stand on the platform. Consequently, a Collider must be added....