Hi all
I have set a collision between 2 objects. So when they collide, i want to temporarily make one of them invisible.
I am using OnTrigger and renderer.Enabled = false. I am stuck about the time component
While AliAzin's answer is very good, the main problem in your method is, that the ...=true part is always called, even if time>3. So the first thing to fix would be:
You can try accumulate Time.deltaTime instead, as Time.time is the absolute time elapsed since the application has run. Edit: The preceding sentence is wrong, Time.time is the amount of time elapsed since start of frame, hence the original code should have work if not for the missing else clause.
Untested code below
private var elapsedTime;
private var invisible:boolean;
public function Update()
{
if (invisible) {
if ( elapsedTime <= 3.0) {
elapsedTime += elapsedTime
else {
invisible = false;
elapsedTime = 0;
gameObject.renderer.enabled=true;
}
}
}
public function SetInvisibleForAWhile()
{
invisible = true;
gameObject.renderer.enabled = false;
}
Or, you can store the starting Time.time, and get the current Time.time, and subtract it to see if it is 3.0.