Skip to content

Instantly share code, notes, and snippets.

@erskingardner
Created June 17, 2011 09:47
Show Gist options
  • Save erskingardner/1031146 to your computer and use it in GitHub Desktop.
Save erskingardner/1031146 to your computer and use it in GitHub Desktop.
var lightSource : GameObject;
var brightnessGuiTrigger : GameObject;
var minIntensity : float;
var maxIntensity : float;
var lightIntensity : float;
private var brightnessSliderOpen = false;
function Start () {
Hide();
}
function Update () {
if (Input.touchCount == 1 && Input.GetTouch(0).tapCount == 2) {
var touch = Input.GetTouch(0);
var ray = Camera.main.ScreenPointToRay(touch.position);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit)) {
if (hit.collider.gameObject == brightnessGuiTrigger) {
if (brightnessSliderOpen) {
Hide();
}
else {
Show();
}
}
}
}
lightSource.light.intensity = lightIntensity;
var dark = Color(87, 77, 71, 1);
var light = Color(248, 231, 212, 1);
var percentOfFullIntensity = 1 - (((maxIntensity - minIntensity) - (lightIntensity - minIntensity)) / (maxIntensity - minIntensity));
Debug.Log(Color.Lerp(dark, light, percentOfFullIntensity));
RenderSettings.ambientLight = Color(87, 77, 71, 1);
}
function OnGUI () {
if (brightnessSliderOpen) {
GUI.Label(Rect((Screen.width / 2) - 32, 10, 100, 30), "Brightness");
lightIntensity = GUI.HorizontalSlider(Rect((Screen.width / 2) - 50, 35, 100, 30), lightIntensity, minIntensity, maxIntensity);
}
}
function Hide () {
brightnessSliderOpen = false;
}
function Show () {
brightnessSliderOpen = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment