当你跳上一个物体时,你如何让一个物体在 Unity 中可见?

How can you make an object visible in Unity when you jump on it?

我正在尝试制作一款游戏,您首先只能看到物体的阴影,一旦您跳上它,它就会让物体可见。有人知道怎么做吗?

游戏截图:

为您的播放器添加“播放器”标签。 您的对象代码可能如下所示:

// 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
    }
}

或者:

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
        }
    }