x


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
more ▼

asked Oct 29 '11 at 11:34 AM

maggot gravatar image

maggot
190 26 28 36

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Oct 29 '11 at 04:20 PM

maggot gravatar image

maggot
190 26 28 36

forgot to add the typeof statement. Thanks to remind!

Oct 29 '11 at 06:08 PM Ludiares
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 29 '11 at 03:42 PM

Ludiares gravatar image

Ludiares
210 2 3

Dont need the addition line for the name, GameObject takes the overload for naming.

GameObject someVar = new GameObject("nameOfMyGameObject");

Hope it helps anyone who stumbles on this! Happy Coding ;}

Mar 07 '12 at 05:57 AM hijinxbassist
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3317
x2987
x425
x141
x86

asked: Oct 29 '11 at 11:34 AM

Seen: 1106 times

Last Updated: Mar 07 '12 at 05:58 AM