How do I add Projector component by code/programatically?

Hello,

I’ve encountered a problem with adding some Projectors to a GameObject… said GameObject has a selfmade script inside, which’s Start() looks like this at the moment:

Projector proj1 = (Projector)gameObject.AddComponent("Projector");

I also tried following, with no success:

Projector proj1 = (Projector)gameObject.AddComponent(typeof(Projector));

/*********************************************************/

Projector proj1 = (Projector)gameObject.AddComponent<Projector>();

/*********************************************************/

Projector proj1 = (Projector)gameObject.AddComponent("Projector");

But nope, not a single projector added. And I need it dynamically, that’s why I don’t wanna do it in the editor… Long story short: I’ve got several buildings that have differing numbers of projectors, so I wanna make that rely on given data and not do it by hand prefab over prefab.

Thanks for any advise, cheers!

Got that, found out I was just looking for a new GameObject as a child on my GameObject when in reality it was added as a Component to the GameObject.

		Projector proj1 = (Projector)gameObject.AddComponent <Projector>();

works just fine!