Unity: How to tag a camera

I just continued my work with the Unity-Framework and run into a basic beginner mistake. I wanted to get the transform values of my camera. So I tried the following lines of code:

Camera cam = Camera.main;
GameObject gameobj = (GameObject)Instantiate(baseobject, cam.transform.position + cam.transform.forward, cam.transform.rotation);

But this gave me the following error message:

NullReferenceException
UnityEngine.Component.get_transform ()

So I then figured out that I need to tag my camera as my MainCamera when I want to use Camera.main. To do such a tag you need to open your camera in the Inspector. Right under the name field is a small dropdown-menu called Tag. There you can set your desired tag for your camera:

Screen Shot 2014-01-18 at 16.22.10

Link: http://answers.unity3d.com/questions/63221/how-to-set-main-camera.html

Yannick Signer

 

Leave a Reply

Your email address will not be published. Required fields are marked *