/Scripts/TextEffect.js
http://acid-and-base.googlecode.com/ · JavaScript · 52 lines · 19 code · 8 blank · 25 comment · 2 complexity · a0612d3665b69c8ff925d7f3ad139e2f MD5 · raw file
- private var colorsR = new Array(255, 0, 0, 255, 255, 0);
- private var colorsG = new Array(0, 255, 0, 255, 0, 255);
- private var colorsB = new Array(0, 0, 255, 0, 255, 255);
- private var index = 0;
- /* Wrote this before I found the Color.Lerp function
- function Interpolate(start, endIndex, percent){
- var percentDec = percent / 100.0;
- var startR : float = start.r;
- var startG : float = start.g;
- var startB : float = start.b;
- var endR : float = colorsR[endIndex];
- var endG : float = colorsG[endIndex];
- var endB : float = colorsB[endIndex];
-
- Debug.Log("percent Dec: " + percentDec);
-
-
- var rVal = Mathf.Round(startR * (1.0-percentDec) + endR * percentDec);
- var gVal = Mathf.Round(startG * (1.0-percentDec) + endG * percentDec);
- var bVal = Mathf.Round(startB * (1.0-percentDec) + endB * percentDec);
- return Color(rVal,gVal,bVal);
-
- }
- */
- private var iterations = 100;
- private var currentIter = 0;
- function Update () {
-
- var next = index+1;
- //reset current to 0 if end of array is reached
- if (next >= colorsR.length) next = 0;
-
- //var newColor = Interpolate(renderer.material.color, index, percentage);
- var oldColor = Color(colorsR[index]/255.0, colorsG[index]/255.0, colorsB[index]/255.0);
- var newColor = oldColor;
- currentIter++;
- //iterates 100 times before moving onto the next color
- if (currentIter >= iterations){
- newColor = Color(colorsR[next]/255.0, colorsG[next]/255.0, colorsB[next]/255.0);
- index = next;
- currentIter = 0;
- }
-
- renderer.material.color = Color.Lerp(renderer.material.color, newColor, Time.deltaTime);
-
- }