- Home /
Renderer Alpha Cutoff
I'm aware of the post by Erich here, but I'm having difficulties implementing this.
I have two planes. One is a "GUI" element and the other will serve as a cool down timer of sorts. This timer is intended to display the cool down left on the ability, like an a MMO. Currently, the code, I think, sets the alpha cutoff and that's it. Naturally, this wouldn't work as intended if it wasn't animated!
Here's what I have:
var maxTime : float = 1.0; var canShoot : boolean = true; var rate : float = 0.0; var animate : boolean = true;
function Start() { maxTime = RClick.reloadTime; renderer.enabled = false; }
function Update () { rate -=Mathf.InverseLerp(1, 0, Mathf.SmoothStep(1, 0, Time.deltaTime * maxTime));
if (animate == true)
{
renderer.material.SetFloat("_Cutoff", rate);
}
if(Input.GetButtonDown( "Fire1" ) && PauseMenu.isPaused == false && canShoot == true)
{
canShoot = false;
renderer.enabled = true;
//renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, 1, (Time.deltaTime / maxTime)));
animate = true;
Reset();
}
}
function Reset() { yield WaitForSeconds (maxTime); renderer.enabled = false; maxTime = RClick.reloadTime; canShoot = true; animate = false; }
Edit: The question is how to fix it so that it animates smoothly over the correct duration (maxTime, ~3 seconds). I've since updated my code to show what I've changed. I've got it animating right now, but it's not for the full duration (0-1 over 3 seconds). It seems like its starting at 0 and going to .3, then starting at .3 then going to .6 etc.
I don't see a question. Regardless, it's not going to work right; color channels are 0-1, not 0-100.