Created
February 8, 2017 23:28
-
-
Save donovankeith/184e88150c358a6ab36361252e1bbbfe to your computer and use it in GitHub Desktop.
Unity Script: Changes light to Red/Green/Blue when user press `R`, `G`, or `B` keys.
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
// RGBLight.cs | |
// Changes light to Red/Green/Blue when user press `R`, `G`, or `B` keys. | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class RGBLight : MonoBehaviour { | |
Light light; | |
// Use this for initialization | |
void Start () { | |
light = GetComponent<Light> (); | |
} | |
// Update is called once per frame | |
void Update () { | |
// Respond to User Keyboard Input | |
// Red | |
if (Input.GetKeyUp (KeyCode.R)) { | |
light.color = Color.red; | |
} | |
// Green | |
else if (Input.GetKeyUp (KeyCode.G)) { | |
light.color = Color.green; | |
} | |
// Blue | |
else if (Input.GetKeyUp (KeyCode.B)) { | |
light.color = Color.blue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment