Skip to content

Instantly share code, notes, and snippets.

@donovankeith
Created February 8, 2017 23:28
Show Gist options
  • Save donovankeith/184e88150c358a6ab36361252e1bbbfe to your computer and use it in GitHub Desktop.
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.
// 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