- Home /
(beginner)unity 5 on collision enter make object visible for a period of time
Hi i am beginner on scripting.
Can you tell me how can i make object renderer enabled for a period of time, if it collide with object name "train"
All I found tutorials is for unity 4.
I am trying to make a warning system for a train pass, when train come, warning lights will be visible for some seconds, then after invisible again.
Comment
Answer by Piorecki · Mar 03, 2016 at 03:24 PM
@acmeydan this is simple script using Coroutines. Remember to add this script and Rigidbody to light and check that all colliders are not triggers.
public class enablemeshrenderer : MonoBehaviour{
public float timeenabled;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Nameoftrainineditor")
{
StartCoroutine(Light());
}
}
IEnumerator Light()
{
this.GetComponent<MeshRenderer>().enabled = true;
yield return new WaitForSeconds(timeenabled);
this.GetComponent<MeshRenderer>().enabled = false;
}
}