Skip to content

Instantly share code, notes, and snippets.

@thebeardphantom
Created May 10, 2015 18:23
Show Gist options
  • Save thebeardphantom/b8aa10165c87dfd6ca28 to your computer and use it in GitHub Desktop.
Save thebeardphantom/b8aa10165c87dfd6ca28 to your computer and use it in GitHub Desktop.
MixColors
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class MixColors : MonoBehaviour {
[SerializeField]
Color[] colors;
[SerializeField]
Image image;
[SerializeField]
float multiplier;
public Color result { get; private set; }
// Update is called once per frame
void Update() {
if(colors == null || colors.Length == 0) {
return;
}
var r = 0f;
var g = 0f;
var b = 0f;
var a = 0f;
foreach(var c in colors) {
r += c.r;
g += c.g;
b += c.b;
a += c.a;
}
r /= colors.Length;
g /= colors.Length;
b /= colors.Length;
a /= colors.Length;
result = new Color(r, g, b, a);
result *= multiplier;
if(image != null) {
image.color = result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment