Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- //Variables START
- //Light Source && Battery Life
- var flashlightLightSource : Light;
- var lightOn : boolean = true;
- var lightDrain : float = 0.1;
- var batteryLife : float = 0.0;
- var maxBatteryLife : float = 2.0;
- //Sound Clips
- //var soundTurnOn : AudioClip;
- //var soundTurnOff : AudioClip;
- //Variables END
- function Start()
- {
- batteryLife = maxBatteryLife;
- flashlightLightSource = GetComponent(Light);
- }
- function Update()
- {
- if(lightOn && batteryLife >= 0)
- {
- batteryLife -= Time.deltaTime * lightDrain;
- }
- if(batteryLife <= 0)
- {
- batteryLife = 0;
- lightOn = false;
- }
- if(batteryLife <= 1)
- {
- flashlightLightSource.light.intensity = 0.6;
- }
- if(batteryLife <= 0.5)
- {
- flashlightLightSource.light.intensity = 0.3;
- }
- if(Input.GetKeyUp(KeyCode.F))
- {
- toggleFlashlight();
- // toggleFlashlightSFX();
- if(lightOn)
- {
- lightOn = false;
- }
- else if(!lightOn && batteryLife >= 0)
- {
- lightOn = true;
- }
- }
- }
- function toggleFlashlight()
- {
- if(lightOn)
- {
- flashlightLightSource.enabled = false;
- }
- else
- {
- flashlightLightSource.enabled = true;
- }
- }
- /*function toggleFlashlightSFX()
- {
- if(flashlightLightSource.enabled)
- {
- audio.clip = soundTurnOn;
- }
- else
- {
- audio.clip = soundTurnOff;
- }
- audio.Play();
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement