Unanswered as of Feb 20, 2014 11:50am PST.
I am trying to use the Index operator on the material color for a basic object using the default material.
Here is the code I am trying to make work but for some reason isn’t:
var i : int;
for (i=0; i<4; i++) {
if (this.rgba *> 1) {*
_ this.rgba = 1;_
* }*
_ else if (this.rgba < 0) {
this.rgba = 0;
* }_
this.renderer.material.color _= this.rgba;
}
Based on [This Link][1] it should work the same as the follow (Which does work):
var i : int;
for (i=0; i<4; i++) {
if (this.rgba > 1) {
this.rgba = 1;
}
else if (this.rgba < 0) {
this.rgba = 0;
}
}
this.renderer.material.color.r = this.rgba[0];
this.renderer.material.color.g = this.rgba[1];
this.renderer.material.color.b = this.rgba[2];
this.renderer.material.color.a = this.rgba[3];
Could someone explain why this isn’t working for me.
I am calling this in my update function.
rgba is a instance variable float[4];
Using JavaScript.
Unity version 4.3.3f1 on Windows 7
Sources that my logic is based on
Unity - Scripting API: Color.this[int]
http://docs.unity3d.com/Documentation/ScriptReference/Material.html*_
*http://docs.unity3d.com/Documentation/ScriptReference/Color.html*_
Update
I have tried another method of achieving this (that works) but I still don’t know why the first method in the post isn’t working (In JAVASCRIPT).
var i : int;
var c : Color = this.renderer.material.color;
for (i=0; i<4; i++) {
if (this.rgba > 1) {
this.rgba = 1;
}
else if (this.rgba < 0) {
this.rgba = 0;
* }_
c _= this.rgba;
}
this.renderer.material.color = c;_
[1]: Unity - Scripting API: Color.this[int]*