using UnityEngine;
[RequireComponent(typeof(Camera))]
[ExecuteInEditMode]
public class MirrorCamera : MonoBehaviour
{
new Camera camera;
public bool Horizontal;
void Awake()
{
camera = GetComponent<Camera>();
}
void OnPreCull()
{
camera.ResetWorldToCameraMatrix();
camera.ResetProjectionMatrix();
Vector3 scale = new Vector3(Horizontal ? -1 : 1, 1, 1);
camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(scale);
}
void OnPreRender()
{
GL.invertCulling = Horizontal;
}
void OnPostRender()
{
GL.invertCulling = false;
}
}
将代码挂在到需要实现镜面显示效果的摄像机物体上,并将Horizontal选为True即可。