Created
November 25, 2013 21:29
-
-
Save jakevsrobots/7649216 to your computer and use it in GitHub Desktop.
Script to toggle a flashlight on and off. Attach this component to an object with a spotlight component. Add an AudioSource so the switch sound will play. Also remember to adjust the ambient color of the scene for darkness: (Edit->Render Settings->Ambient color).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Flashlight : MonoBehaviour { | |
public AudioClip switchSound; | |
void Update () { | |
if(Input.GetKeyDown(KeyCode.F)) | |
{ | |
audio.PlayOneShot(switchSound); | |
if(light.enabled) | |
{ | |
light.enabled = false; | |
} | |
else | |
{ | |
light.enabled = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment