Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Creating the GameObject
Open tht Scene
First of all, let's open the scene we worked on last lesson (or we downloaded).
Creating the Coin
Let's create and empty gameobject (GameObject > CreateEmpty), posizioniamolo in (0, 0, 0) and rename it PickUpCoin.
From the Standard Assets > Prototyping > Models folder, drag PickupPrototype01x01x01 inside PickUpCoin, so that it's a child element.
We are not adding the coin prefab because we are only interested in the model. We will add the Collider later on.
Select PickupPrototype01x01x01, and rename it Coin, position it in (0, 1, 0) and scale it to 30% (0.3, 0.3, 0.3).
With Coin selected, click Add Component in the Inspector panel and select Scripts > UnityStandardAssets.Utility > AutoMoveAndRotate to add a rotation effect to the coin.
Open the Rotate Degrees Per Second field and change Y to 100.
As a last step, change the Mesh Renderer from Pink Smooth to Yellow Smooth.
The final result should be similar to the one shown in the image below.
Playing the scene should start the coin rotation.
Save the scene.
Add the Trigger
Select the coin parent del coin (PickUpCoin): we are going to add a Collider so we can activate a trigger when the character enters inside it.
Let's click Add Component and select Physics > Sphere Collider: change it in a Trigger checking the Is Trigger value and, in the Center field, change the Y value to 1, so that it will be in the same position as the coin element.
We are using a Sphere Collider as it is pretty good for the ritating coin.
We are now ready to add some interactivity the the coin.