Time for action – creating two GameObjects and a new script
I want you to create one script that will be attached to two GameObjects. The script will have two methods that will cause the GameObjects to rotate left and right. This will show you that from a single script file, two separate Component objects will be created in the memory. Each Component object is a separate instance object with no absolutely knowledge of the other.
- In your Scene, create two GameObjects,
Capsule
andCube
. - Add a Directional Light to the Scene so you can easily see the GameObjects.
- Here's my Scene as an example:
- Create a new C# Script and name it Spinner.
- Code the script as ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.