- Home /
Turn an objects mesh renderer on upon collision.
I've never accessed mesh renderers from script before so I don't know if this is how to do it, it doesn't appear to be working.
using UnityEngine;
using System.Collections;
public class MeshRendererEnabler : MonoBehaviour {
void OnCollisionEnter(Collision other) {
if(other.collider.name == "InvisibleBlock")
{
renderer.enabled = true;
}
}
}
Comment
Best Answer
Answer by MrTiger · Dec 08, 2014 at 07:38 PM
Try this script .. attach this c# script to a cube or any game object and add a rigidbody to it and uncheck "use gravity" ..create another cube do the same but don't attach the script and uncheck the mesh renderer and name that cube as "InvisibleBlock"
using UnityEngine;
using System.Collections;
public class MeshRendererEnabler : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
if(other.collider.name == "InvisibleBlock")
{
other.gameObject.GetComponent<MeshRenderer>().enabled = true;
}
}
}
now make them collide each other
Your answer
Follow this Question
Related Questions
How to generate a NavMesh only with colliders? 5 Answers
2D collider wont collide with mesh 0 Answers
How Can I switch between 2 colliders in my 2D Game? 1 Answer
Mesh collider cost 1 Answer
Tile-based approach in Unity 1 Answer