- Home /
Gun Barrel To Get Hot - Change _Tint
Hello,
I'm working on a weapon that, when you fire continuously, the barrel gets hot ... So it turns 'red'. The current material is a Partiles/Alpha Blended, and I want to increase the red _Tint of the material.
I've tried using Lerp.Mathf, but that only occurs once. What I want , is to loop this action. So you fire ... barrel gets hot (turns red), stop firing ... barrel cools down (back to default).
So:
Lerp.Mathf - only seems to occurs once
iTween - only supports _Color ... not _Tint
How else can I have a 'fade' affect?
Basically:
var firing : boolean;
if(firing == true){
//fade in red tint
}
else{
//fade out red tint to default
}
Would appreciate any help.
Thanks
Answer by syclamoth · Jan 22, 2012 at 11:35 PM
Use Lerp. There's nothing stopping you from fading it in and out- you just have to think about it differently!
var firing : boolean;
var heatUpRate : float = 0.3;
var coolDownRate : float = 0.4;
private var barrelHeat : float = 0;
function Update()
{
if(firing)
{
barrelHeat = Mathf.Clamp01(barrelHeat + (heatUpRate * Time.smoothDeltaTime));
} else {
barrelHeat = Mathf.Clamp01(barrelHeat - (coolDownRate * Time.smoothDeltaTime));
}
renderer.material.SetFloat("_Tint", barrelHeat);
}
Your answer
Follow this Question
Related Questions
rendering mode "Fade" results in culling disorder? 0 Answers
Fading in between two materials overtime? 3 Answers
Fading Materials 4 Answers
How do you tint a Mobile Diffuse material? 1 Answer
Fading a GameObject in/out 1 Answer