Hey Unity Answers,
I’m having a problem inside one of my scripts. I want to constantly change the color of a material of a gameObject. I do this by changing the value for color.b. I intended to “pingpong” that value between 0 and 254, however after trying to debug it I found out it does not pingpong back and forth but instead keeps adding the number bcolor on and on. My script is as follows:
function Update () {
var bcolor: int = Mathf.PingPong(Time.time*50, 254);
print(bcolor);
gameObject.transform.renderer.material.color.b = bcolor;
}
so first I assign variable bcolor to an integer containing a constantly changing value between 0 and 254. After, I checked it by printing this value for bcolor, this gave me what I wanted (0 to 254 and back). In the third line I tried to assign this integer value to the “b” component of the color of the material. However, during playtime I checked this value and it starts at 0 but keeps adding (probably every frame) the number bcolor to this existing value in stead of assigning bcolor to the color.b… so after ~5 seconds the value for color.b is around 30000, while the maximum is actually 255… Anybody know what i’m doing wrong? I know a way easier way is to use animations but I haven’t covered that yet.