Hello everybody ![]()
I’m just trying to make my first little game with unity, now I’m still learning this and I’m not very used to the class architecture of this engine yet.
I’m trying to initialize some lights in my scene, using a C# script. Now I took an example codesnippet frome here, which is Javascript, and tryed to translate it into C#.
This came out:
private void init_light() {
GameObject lightGameObject = new GameObject("The Light");
// Add the light component
light = lightGameObject.AddComponent(Light);
// Set color and position
lightGameObject.light.color = Color.blue;
// Set the position (or any transform property) after
// adding the light component.
lightGameObject.transform.position = new Vector3(0, 5, 0);
}
Now in line 5 the Compiler gives me this Error:
error CS0119: Expression denotes a
type', where avariable’,value' ormethod group’ was expected
I also tried to change the AddComponent(Light) to AddComponent(new Light()), but then i get this:
Assets/main/main.cs(29,41): error CS1502: The best overloaded method match for `UnityEngine.GameObject.AddComponent(string)’ has some invalid arguments
When i change Light to “light”, i don’t get any lightobject.
Can anybody tell me how to do it? I’d also like know why to use Javascript anyways, isn’t C# faster?
Thanks a lot, that worked out for me. :) I didn't see the dropdown yet, I was wondering why all the documentation is written in JavaScript, thanks for that too haha
– Dray