Created
February 8, 2017 23:31
-
-
Save donovankeith/a8688996d942ee0391f98e4904370c54 to your computer and use it in GitHub Desktop.
C# Unity Script: Toggles a light on/off when user presses the `L` key.
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
// ToggleLight.cs | |
// Turns the light component of this object on/off when the user presses and releases the `L` key. | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ToggleLight : MonoBehaviour { | |
Light light; | |
// Use this for initialization | |
void Start () { | |
light = GetComponent<Light> (); | |
} | |
// Update is called once per frame | |
void Update () { | |
// Toggle light on/off when L key is pressed. | |
if (Input.GetKeyUp (KeyCode.L)) { | |
light.enabled = !light.enabled; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this saved my project