- Home /
Making an object blinking for some time, then dissapearing
I have some empty object, just a model. How can I make it be invisible for some random time (15-30 sec.), then appear and dissapear repeatedly, then dissapear again for 15-30 sec?
this feels like a "please do this for me" question. please show some level of effort, and edit your question before the down-votes start co$$anonymous$$g.
hint. yield WaitForSeconds(float) will probably get you most of the way there.
how can i make it blink on trigger? i tried putting the startcoroutine() in the OnTriggerEnter function but the coroutine works only once. can someone help me pls?
Answer by markedagain · Jul 11, 2013 at 07:50 PM
http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html
these links should get u started. as for writing the script for you, i dont think nobody will rise to the occasion to just write scripts for someone not trying to learn it themselves, there are other threads for does.
give it a try if , post what u got, if u on the wrong path , we will be more than happy to write u the code and show u the proper path
I've got a timer, but I have no idea how to enable/disable the renderer. Could you help please?
Answer by MicroEyes · Jul 12, 2013 at 07:00 AM
Hope this Helps..
public GameObject m_playerRendererRef;
IEnumerator DoIT()
{
//Visible initially
m_playerRendererRef.enabled = false; //Making invisible
yield return new WaitForSeconds(2.0f); //for 2 secs
m_playerRendererRef.enabled = true; //Making visible
yield return new WaitForSeconds(1.0f); //for 1 secs
m_playerRendererRef.enabled = false; //Making invisible again
yield return new WaitForSeconds(1.5f); //for 1.5 secs
}
there are a few notes that should be made about this script:
1 this script assumes that the model (probably also assumed to be complex) is a child, or an external GameObject to where this script is placed.
2 this script assumes that the reference m_playerRendererRef
is setup beforehand probably through the inspector. considering that turning off a GameObject through enabled [deprecated] means that scripts on that object stop being called, but references can still continue (the "m_"
portion of the name is an archaic na$$anonymous$$g convention)
a suggestion would be: to change the data type of m_playerRendererRef
to Renderer ins$$anonymous$$d of GameObject. this would remove part of the assumption of note 1. if the object is rather complex (more then 1 mesh, or has mesh in children) then leave it the way it is. otherwise you can even place it on the object.
as an addition to the script provided if you would still like the "randomness" then WaitForSeconds takes in a float variable, and can even take in the return value of a Random.Range(float, float):float meaning that by replacing the literals given in the WaitForSeconds arguments you can achieve your:
"make it be invisible for some random time (15-30 sec.), then appear and dissapear repeatedly, then dissapear again for 15-30 sec"