OnCollisionEnter help - looking to have mesh appear as player enters in a certain zone
Hi all,
Noober here, apologies in advance.
I have created the objects in unity and added my video textures. I have also disabled the mesh renderers on each object making them invisible as of now. I have also put sphere colliders around each object. My question is how would I make them appear and play as soon as the VR player enters the collider zone?
Answer by Jawchewa · Apr 28, 2017 at 02:41 AM
The easy way to make them Mesh Renderers reappear when the player enters the collider would be a script on the object with something like this:
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("Player"))
{
gameObject.GetComponent<MeshRenderer>().enabled = true;
}
}
This would enable the mesh renderer of an object when it comes into contact with a gameobject with the tag of "Player."
@Jawchewa Awesome, thanks a mil, helps tremendously. Would you know if my movieTextures will begin to play as well or will I need to make the movieTexture code also be true in order for it to play?
I'm not super experience with $$anonymous$$ovie Textures, but from looking at the documentation, it looks like you will have to tell it to play yourself with something like this:
(($$anonymous$$ovieTexture)GetComponent<$$anonymous$$eshRenderer>().material.mainTexture).Play();
Here's the documentation for more details about that:
https://docs.unity3d.com/$$anonymous$$anual/class-$$anonymous$$ovieTexture.html