My name's Ray, and this is Ray of Ideas discussing a simple tips to make a mirror in a 2D world in Unity.
Video version:
Create these gameobjects, and name them as follows:
*Be cautious, make sure the Z coordinate of the position of the Mirror is 0, else the camera might not capture it by accident.
Also, prepare a sprite that matches the inner side on your mirror. It will be used as the mask.
Make a camera with Projection: Orthographic. Set its Projection Size according to your will. Don't forget to set its position of Z coordinate below zero.
1. Assign your render texture as the mirroring camera's Output Texture. The ratio of your camera will be adjusted with the render texture's Size.
2. Set the MirroringSprite's material to the new material you have made.
3. Add SpriteMask component to your Mirror. Assign the sprite that matches the inner side of your mirror as the SpriteMask's sprite.
4. Move MirroringSprite's location inside the Mirror. Change its SpriteRenderer's Mask Interaction to Visible Inside Mask. Change the Order in Layer above Mirror's order (above zero).
Practically, by this point, the mirror works just fine rendering parts of what the main camera is rendering. So, to make it less obvious, we need to add some extra sprites that can only be seen inside the mirror.
To make this example more clear, I'll move the mirror inside my own scene.
After that, I adjust the mirroring camera's Size and position, the MirroringSprite's scale, and also the renderer texture's Size (then reassign it) to make it more realistic.
As you can see, there's a towel behind the player that's also rendered in the mirror. We need to cover that using some sprites that are placed inside MirrorWorld.
1. Use the GrayBox, then cover the towel. Make sure GrayBox's Order in Layer is higher than any object that it is covering.
Once we have covered it, our main camera also can't see the towel. So, we have to make an exception for the main camera to ignore some objects.
2. Make a new Layer, name it "Mirror" (or anything you want).
3. Set MainCamera's CullingMask to everything except Mirror layer
4. Set MirrorWorld's Layer to Mirror.
5. Add more objects into MirrorWorld
2. If you want to make a mirror that renderer's the opposite direction of your character, there's a way that I know: Rotate the mirroring camera 180° in Y, the move its position of Z to the other side (usually your camera has minus value on Z axis, but make it positive now).
____
Thank you for reading!
Share the knowledge everywhere if you want to~
See ya!
___
For more insights, check my posts in
▶️ YouTube : https://www.youtube.com/channel/UChcrY_MMjhUVin4tNzJzmZg
💡 Minds : https://www.minds.com/rayofideas/
🐤 Twitter : https://twitter.com/ray_ideas
📷 Instagram : https://www.instagram.com/rayofideas
----
Thank you for stopping by!