Skip to Content
Learning C# by Developing Games with Unity 3D Beginner's Guide
book

Learning C# by Developing Games with Unity 3D Beginner's Guide

by Terry Norton
September 2013
Beginner content levelBeginner
292 pages
6h 19m
English
Packt Publishing
Content preview from Learning C# by Developing Games with Unity 3D Beginner's Guide

Time for action – trying drag-and-drop to assign a GameObject

Let's change a few lines of code in LearningScript to show how to assign the Capsule GameObject to the variable capsuleGO using drag-and-drop.

  1. Either comment out line 11 using 2 forward slashes (//), or remove it.
  2. On line 6, add the access modifier public like this: public GameObject capsuleGO;
  3. Save the file.
  4. In Unity, select the Main Camera GameObject.
  5. Drag the Capsule to the Capsule GO field in the Inspector. The following screenshot shows how this is done.
  6. Click on Play.
Time for action – trying drag-and-drop to assign a GameObject

What just happened?

The Capsule GameObject is now assigned to the capsuleGO variable. We didn't have to write the code ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning C# by Developing Games with Unity 2019 - Fourth Edition

Learning C# by Developing Games with Unity 2019 - Fourth Edition

Harrison Ferrone
Unity 3D Game Development

Unity 3D Game Development

Anthony Davis, Travis Baptiste, Russell Craig, Ryan Stunkel

Publisher Resources

ISBN: 9781849696586Other