- Home /
object dissappear and reappear
hi, last night i was playing sanandreas and observed a thing that the windows of the building are covered by plane mesh which are self Illuminated they disappear in day and reappear at night which gives a glow effect of windows at night is it possible in unity that a object i disappeared for some time and then reappear for some time if yes how can i do this
Answer by CodeMasterMike · Dec 13, 2012 at 02:17 PM
To make it really easy, you disable the object that you want to disappear, and after a given time make it appear again through enable its renderer class. Something like this pseudo code:
private float m_waitInSeconds = 100.0f;
private float StartTime = 0.0f;
public GameObject playerObject = null;
Start()
{
// The time at this very moment, plus the 100 seconds we want to wait.
StartTime = Time.time + m_waitInSeconds;
}
update()
{
// Wait until its time
if(StartTime <= Time.time)
{
// Make it visible
if(playerObject.renderer.enabled == false)
{
playerObject.renderer.enabled = true;
}
else // Make it invisible
{
playerObject.renderer.enabled = false;
}
// Make it wait another 100 seconds until we switch it again.
StartTime = Time.time + m_waitInSeconds;
}
}
Good luck!
Your answer
Follow this Question
Related Questions
How would I make an object disappear after a set amount of time? 3 Answers
Same script not working on all objects 1 Answer
Objects Appearing 1 Answer
Object appear and disappear on command 1 Answer
Guitexture appear/disappear 1 Answer