Ok, I am at a loss. I have these two objects, both using the particle/additive shader. They are the children of my main ui element. They are supposed to update on the point score, which they poll for. They are supposed to flash (become visible) when certain criteria are met. But for whatever reason, they aren’t doing a thing. I know it has to be something simple but I’m just not seeing it, I need another set of eyes on this. Any ideas? Thanks in advance.
var isPositive = true;
private var PointTotal : int;
private var LastPointTotal : int;
private var Trans = Color.clear;
private var White = Color.white;
private var count = 0;
function Awake()
{
//pre populate values and make trans.
PointTotal = userInterface.Points;
LastPointTotal = PointTotal;
renderer.material.color = Trans;
}
function Update()
{
//count ++;
//if(count < 30)
//{
// count = 0;
// return;
//}
PointTotal = userInterface.Points; //Update point total.
if(isPositive) //is the green switch
{
if(PointTotal > LastPointTotal) //points have gone up
{
gameObject.renderer.material.color = White;
Debug.Log("You should see something!");
}
else //points have gone down
{
gameObject.renderer.material.color = Trans;
}
}
else //is the red switch
{
if(PointTotal < LastPointTotal) //points have gone down
{
gameObject.renderer.material.color = White;
}
else //points have gone up
{
gameObject.renderer.material.color = Trans;
}
}
LastPointTotal = PointTotal;
}
if(PointTotal > LastPointTotal) //points have gone up
{
gameObject.renderer.material.color = White;
Debug.Log("You should see something!");
}
else
{
gameObject.renderer.material.color = Trans;
}
Where your “points have gone up/down” comments are you’ve actually got the behaviour “points have gone up/down or remained the same”.
What’s happening at the moment.
- Points go up, colour gets changed to white.
- The next update a very short time latter - if the points haven’t gone up again since the last update the colour gets changed back to transparent.
It’s probably changing to white and then going back to transparent to fast to even see the change. Same with the other block.
I don’t know if there are other problems as well, but that’s the immediately obvious one.
Thanks for the reply. I thought that might be the case as well so I added a yield of a few seconds, no change in the view. If I set the object to be white, the renderer.material.color = Trans; in the Awake function fails to make it transparent. It gives me no warnings or failures.
edit sorry, my brain is a bit useless. Thanks for pointing out the third condition, that was wasting a lot of cycles, but sadly not the point of failure.
Currently, the awake function does not have a gameobject attached to the material, whereas the Update ones do, just wondering if that’s intentional?:
awake(){
renderer.material.color = Trans; //mising gameobject??
}
update(){
...
gameObject.renderer.material.color = White; gameObject.renderer.material.color = Trans; gameObject.renderer.material.color =White;gameObject.renderer.material.color = Trans;
}
It was intentional, I was testing to see if it made any difference. It didn’t. I did however figure out what the problem was. The color for the shader was called Tint Color so I had to use…
renderer.material.SetColor("_TintColor", Trans);
I had totally overlooked it.
Great, I was just about to post how I got it working too 
I changed the shader to a simple transparent diffuse and added this:
public var turnWhite:boolean = false;
private var Trans = Color(0.0, 0.0, 0.0, 0.0);
private var White = Color(1.0, 1.0, 1.0, 1.0);
function Awake()
{
}
function Update()
{
if(turnWhite) //points have gone up
{
renderer.material.color = White;
}
else //points have gone down
{
renderer.material.color = Trans;
}
}