I’m trying to use GUI buttons as switches between two lights; a flashlight, and the sun. I also want the buttons that operate the flashlight rotation to disappear when the sun is activated. However, I can’t get the flashlight and buttons to become invisible. Also the reset button, which is supposed to reset the flashlight’s position as well as the sliders, isn’t working properly; it resets the sliders without moving the flashlight.
var fLight: Light;
var sunLight: Light;
var flashlight: GameObject;
private var fon = false;
private var son = false;
var startPosition : Vector3;
var startRotation : Quaternion;
var vSliderValue: float = 0.0;
var hSliderValue: float = 0.0;
private var reset = false; // object resets if true;
function Start()
{
fLight.light.intensity = .51;
sunLight.light.intensity = 0;
startPosition = transform.position;
startRotation = transform.rotation;
}
function Update()
{
if (fon) sunLight.light.intensity = 0;
if (fon) fLight.light.intensity = .51;
if (fon) flashlight.gameObject.active = true;
if (son) fLight.light.intensity = 0;
if (son) sunLight.light.intensity = .5;
if (son) flashlight.gameObject.active = false;
if (son) reset.active = false;
if (son) hSliderValue.active = false;
if (son) vSliderValue.active = false;
if (vSliderValue) flashlight.transform.rotation.eulerAngles.x = vSliderValue;
if (hSliderValue) flashlight.transform.rotation.eulerAngles.z = hSliderValue;
if (reset) transform.position = startPosition;
if (reset) transform.rotation = startRotation;
if (reset) vSliderValue = 0;
if (reset) hSliderValue = 0;
}
function OnGUI()
{
vSliderValue = GUI.VerticalSlider(Rect(10,20,10,100), vSliderValue, -50, 50);
hSliderValue = GUI.HorizontalSlider(Rect(20,10,100,10), hSliderValue, -50, 50);
reset = GUI.Button(Rect(40,40,50,50), "Reset");
fon = GUI.Button(Rect(900,10,100,100), "Flashlight");
son = GUI.Button(Rect(900,120,100,100), "Sun Light");
}