- Home /
Adding lights and cameras to scenes with cSharp script
How do I add lights and cameras to scenes using cSharp script. Here's how I did it in javascript :
var light005GameObject : GameObject = new GameObject("PointLight005");
light005GameObject.AddComponent(Light); // etc
var camera001GameObject : GameObject = new GameObject("CameraTest");
camera001GameObject.AddComponent(Camera); // etc
Comment
Best Answer
Answer by maggot · Oct 29, 2011 at 04:20 PM
WOOT! I got it working with one addition to your code
light005GameObject.AddComponent(Light);
should be
light005GameObject.AddComponent(typeof(Light));
and the same for adding Camera
forgot to add the typeof statement. Thanks to re$$anonymous$$d!
Answer by Ludiares.du · Oct 29, 2011 at 03:42 PM
it's almost the same. you don't declare the type of variable after it, it is declared before.
GameObject light005GameObject = new GameObject();
light005GameObject.name = "light005";
light005GameObject.AddComponent(Light);
And it would be the same for cameras.
Dont need the addition line for the name, GameObject takes the overload for na$$anonymous$$g.
GameObject someVar = new GameObject("nameOf$$anonymous$$yGameObject");
Hope it helps anyone who stumbles on this! Happy Coding ;}