Last active
August 3, 2017 13:34
-
-
Save elringus/43bd4455c631f331d650b30ad36efb2c to your computer and use it in GitHub Desktop.
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.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