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.

  1. In your Scene, create two GameObjects, Capsule and Cube.
  2. Add a Directional Light to the Scene so you can easily see the GameObjects.
  3. Here's my Scene as an example:
    Time for action – creating two GameObjects and a new script
  4. Create a new C# Script and name it Spinner.
  5. 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.