Join Kelley Hecker for an in-depth discussion in this video Making a coin float, part of Unity: Scripting with C#.
- Now that the coins are spinning,…I think they should also hover…up and down a bit.…I've gone ahead and added a few more coins…to my scene as well.…Remember that if you're starting directly…from the exercise files instead of continuing…from the previous video, you'll need to import…the standard assets for Unity 4.6 package…from the asset store and drag in…the ThirdPersonCharacter…and FreeLookCameraRig pre-fabs…like we did earlier in this chapter.…Go ahead and open the Coin script.…To make the coin float,…rather than modifying the coin's rotation,…this time I'm going to modify its position.…
We'll add two new variables.…The first one, floatSpeed,…will control how fast the coin moves up and down.…This will be in up and down cycles per second.…The second variable, movementDistance,…will be the maximum distance the coin can move…up and down from its center point.…
Both of these will appear in the inspector…because we used SerializeField…before the declaration.…I'm also going to add two private variables…that don't need to appear in the inspector…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Q: Why am I getting a script compile error when trying to load the exercise files?
A: This course was recorded in Unity 4.6, and Unity has since released Unity 5. There are two items to address for Unity 5 users.
Q: Why can't I see the Render Settings option in the Edit menu?
A: The Render Settings options have been moved in Unity 5. You can access them by going to the Window menu and choosing Lighting. In the window that loads, Render Settings can be found under the Scene tab.