/Scripts/TextEffect.js
JavaScript | 52 lines | 19 code | 8 blank | 25 comment | 2 complexity | a0612d3665b69c8ff925d7f3ad139e2f MD5 | raw file
1private var colorsR = new Array(255, 0, 0, 255, 255, 0); 2private var colorsG = new Array(0, 255, 0, 255, 0, 255); 3private var colorsB = new Array(0, 0, 255, 0, 255, 255); 4private var index = 0; 5 6/* Wrote this before I found the Color.Lerp function 7function Interpolate(start, endIndex, percent){ 8 var percentDec = percent / 100.0; 9 var startR : float = start.r; 10 var startG : float = start.g; 11 var startB : float = start.b; 12 var endR : float = colorsR[endIndex]; 13 var endG : float = colorsG[endIndex]; 14 var endB : float = colorsB[endIndex]; 15 16 Debug.Log("percent Dec: " + percentDec); 17 18 19 var rVal = Mathf.Round(startR * (1.0-percentDec) + endR * percentDec); 20 var gVal = Mathf.Round(startG * (1.0-percentDec) + endG * percentDec); 21 var bVal = Mathf.Round(startB * (1.0-percentDec) + endB * percentDec); 22 23 24 return Color(rVal,gVal,bVal); 25 26} 27*/ 28 29private var iterations = 100; 30private var currentIter = 0; 31 32function Update () { 33 34 var next = index+1; 35 //reset current to 0 if end of array is reached 36 if (next >= colorsR.length) next = 0; 37 38 //var newColor = Interpolate(renderer.material.color, index, percentage); 39 var oldColor = Color(colorsR[index]/255.0, colorsG[index]/255.0, colorsB[index]/255.0); 40 var newColor = oldColor; 41 currentIter++; 42 //iterates 100 times before moving onto the next color 43 if (currentIter >= iterations){ 44 newColor = Color(colorsR[next]/255.0, colorsG[next]/255.0, colorsB[next]/255.0); 45 index = next; 46 currentIter = 0; 47 } 48 49 renderer.material.color = Color.Lerp(renderer.material.color, newColor, Time.deltaTime); 50 51} 52