Let's fix that mirror effect. We need to flip the image rendered by Camera 2 - mirror for the x axis (horizontally). We can do that by writing a C# script class that multiplies the camera's project matrix by a Vector3 of (-1, 1, 1). Note that the first -1 means the x values are flipped horizontally:
Figure 11.16 – Our mirror effect working after a horizontal flip
Write the following in a new C# script class, called FlipCamera.cs. Then, add an instance as a component to Camera 2 - mirror:
using UnityEngine;
public class FlipCamera : MonoBehaviour
{
private Camera _camera;
void Awake() {
_camera = GetComponent<Camera>();
}
void OnPreCull () {
_camera.ResetWorldToCameraMatrix ();
_camera.ResetProjectionMatrix ();
_camera.projectionMatrix = _camera.projectionMatrix * Matrix4x4.Scale(new
Vector3 (-1, 1, 1));
}
void OnPreRender () {
GL.invertCulling...