Game Development Reference
In-Depth Information
Note This prefab Question Coin seems a little large. You can resize it using the Transform component Scale
property for the purpose of rapid prototyping, but remember that for your final game art, it is better to size the
models appropriately prior to importing them.
The Question Coin will really catch the player's eye if it is moving. In the Project panel, create a
new script and name it SpinCoin. Double-click to open it in MonoDevelop and edit the code to the
following:
#pragma strict
public var spinSpeed : float = 50;
function Update () {
transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime);
}
This is a simple rotation animation that you've been introduced to before. It breaks down as follows:
(1) public var spinSpeed : float = 50;
Declares a public spinSpeed float variable that you can access through the Inspector at runtime to
adjust the rate of rotation of the Question Coin game object.
(2) transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime);
Each frame, update the Question Coin's Transform.rotation around the Vector3.up axis (the y axis)
multiplied by the spinSpeed factor and smoothed with Time.deltaTime . If there was no spinSpeed
factor, the coin would rotate at a rate of one degree per second.
Save the script and attach it to the Question Coin. Save the scene and play. Now the coin definitely
stands out as an object of interest as it spins in place.
If you dig a little deeper into the Prototyping ➤ Prefabs folder, you will come across the Compound
Prefabs folder (Figure 6-14 ). This has some box piles and smash platforms where the player
character and boxes respond to collisions with each other, and super-cool tracks, ramps, and steps.
Search WWH ::




Custom Search