Skip to content

Instantly share code, notes, and snippets.

@elringus
Last active August 3, 2017 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elringus/43bd4455c631f331d650b30ad36efb2c to your computer and use it in GitHub Desktop.
Save elringus/43bd4455c631f331d650b30ad36efb2c to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections.Generic;
[System.Serializable]
public struct ColorMapping
{
public KeyCode KeyCode;
public Color Color;
}
[RequireComponent(typeof(Renderer))]
public class ColorChange : MonoBehaviour
{
public List<ColorMapping> ColorMappings = new List<ColorMapping>();
private new Renderer renderer;
private void Awake ()
{
renderer = GetComponent<Renderer>();
}
private void Update ()
{
foreach (var colorMapping in ColorMappings)
{
if (Input.GetKeyDown(colorMapping.KeyCode))
{
renderer.material.color = colorMapping.Color;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment