Solution 1 :
Add a “Player” tag to your player.
Your code for the objects would probably look something like this:
// SerializeField means that the variable will show up in the inspector
private MeshRenderer renderer; // The Mesh Renderer is the component that makes objects visible
private void Start()
{
renderer = GetComponent<MeshRenderer>(); // Get the Mesh Renderer that is attached to this GameObject
renderer.enabled = false; // Disable the renderer so that it is invisisble
}
private void OnCollisionEnter(Collision other) // When the object collides with something
{
if (other.gameObject.CompareTag("Player")) // See if the GameObject that we collided with has the tag "Player"
{
renderer.enabled = true; // Enable the renderer, making the GameObject invisible
}
}
Or:
private MeshRenderer renderer; // The Mesh Renderer is the component that makes objects visible
[SerializeField] Material invisibleMaterial; // A invisible material
[SerializeField] Material defaultMaterial; // The default, visible material
private void Start()
{
renderer = GetComponent<MeshRenderer>(); // Get the Mesh Renderer that is attached to this GameObject
renderer.material = invisibleMaterial; // Sets the material of the object to the invisible on, rendering it invisible
}
private void OnCollisionEnter(Collision other) // When the object collides with something
{
if (other.gameObject.CompareTag("Player")) // See if the GameObject that we collided with has the tag "Player"
{
renderer.material = defaultMaterial; // Sets the material to the default material
}
}
Problem :
I’m trying to make a game where you first only see the shadows of the objects, and as soon as you jump on it, it should make the object visible. Does anyone know how to do that?
Screnshot from Game:
Comments
Comment posted by Malphegal
You can change its