Couple things, here. You were correct in that you need a variable to change the color, but what you do is make the variable equal to the renderer color, then change that variable, then make the renderer color equal to the changed variable.
The other thing that won’t work is Lerp needs a loop to function. It either needs to be in an update, or in a loop in a coroutine. The trigger is a one off kind of thing.
I don’t use them much but your variable is changing so use a while loop or something:
while(houseColor.a >=0){
houseColor.a = Mathf.Lerp (0f, 255f, transitionSpeed);
houseRenderer.color = houseColor;
yield return new waitforseconds(time);//look this up because I can't remember the syntax
}
I have no idea if that will work or not, I just know it needs to be in a loop. Good luck. I don’t think it will break out of the loop at zero, so you would have to do something about that.
Would it work if I made the “OnTrigger” events set a boolean value, and then based on that boolean, do the alpha changes in Update?
I tried doing that, but so far it doesn’t seem to be working. The color just changed to black, and the alpha stays the same. And the color changes right at the start, even though I’m not altering anything other than the alpha.
I also tried turning the Color variables to floats, so the only information I would be handling, would be the alpha value for the renderers. But that doesn’t seem to be working either.
Did you use a coroutine? The first thing to do is to just try setting the alpha instantly to zero in the trigger to make sure that part is working. Next, use a coroutine or update to lerp it. It’s not going to matter if you use update or a coroutine, that’s up to you.
The stuff in Start turned out to be useless, so I just removed the whole Start. I replaced the first numbers in the Lerps, with the Color variables’ alpha, so instead of going from the maximum to the minimum in the first one, it goes from the current to the minimum. And same for the second one except opposite.
The last else was also redundant, so I just made the whole thing a simple if/else, which also makes the code a whole lot easier to read.
Now when I enter the trigger, it smoothly turns down the alpha, but when I leave, it instantly jumps to full (255).
Any idea why that is? I mean, why is alpha clamped to 0-1 when changing it in script, even though the actual value in the color picker can go up to 255?