Hello,
I am trying to create 3 kind of lamps and 2 of them you can control in a GUI.
- The point light you can change the color by rgb values.
- The directional light you can change the intensity of.
But when I run my code it creates 2 times each lamp and also 2 times the GUI
GameObject cube;
GameObject capsule;
GameObject sphere;
GameObject plane;
GameObject pointLightGameObject;
GameObject spotLightGameObject;
GameObject diLightGameObject;
Light diLightComp;
Light pointLightComp;
Light spotLightComp;
float timeCounter = 0;
// Use this for initialization
void Start () {
//Lights
//Directional Light
diLightGameObject = new GameObject("Directional Light");
diLightComp = diLightGameObject.AddComponent<Light>();
.....
//Point light
pointLightGameObject = new GameObject("point Light");
pointLightComp = pointLightGameObject.AddComponent<Light>();
....
//Spot Light
spotLightGameObject = new GameObject("spot Light");
spotLightComp = spotLightGameObject.AddComponent<Light>();
....
}
// Update is called once per frame
void Update () {
timeCounter += Time.deltaTime;
float x = Mathf.Cos(timeCounter) - 1f;
float y = 0;
float z = Mathf.Sin(timeCounter) + 1f;
pointLightGameObject.transform.position = new Vector3(x, y, z);
}
float r = 1f;
float g = 0f;
float b = 1f;
void OnGUI()
{
GUI.Box(new Rect(10, 10, 140, 100), "RGB point light - changer");
diLightComp.intensity = GUI.HorizontalSlider(new Rect(20, 100, 100, 30), diLightComp.intensity, 0.0f, 10.0f);
r = GUI.HorizontalSlider(new Rect(20, 40, 100, 30), r, 0.0f, 1.0f);
g = GUI.HorizontalSlider(new Rect(20, 60, 100, 30), g, 0.0f, 1.0f);
b = GUI.HorizontalSlider(new Rect(20, 80, 100, 30), b, 0.0f, 1.0f);
pointLightComp.color = new Color(r, g, b);
}
What is the reason of this and how can i fix this problem ?
Thanks in advance.
Sven