[Unity] How to show the image of a sub-camera on “Render Texture”.

This time, I’ll introduce how to create sub-camera like following image which is my released windows’ game ‘Merlion Adventure for windows’.
This game have the 2nd window at right bottom which is view of the game scene from the top.

(By the way, this ‘Merlion Adventure for windows’ is released from Microsoft Store. Please also try it.)

[Link: https://www.microsoft.com/en-us/p/merlion-adventure/9p2tzw95xsm1?activetab=pivot%3aoverviewtab]


[The way to show an image of sub-camera]

There are some ways to realize that kind of sub screen. This time, I’ll recommend one way which is using Raw Image to show the second camera’s image. It’s very easy way and it can be fitted on the UI’s fixed size.
It means that in my case, I want to put an image of woody flame around the sub-camera’s image. Therefore it’s needed to fix the sub-camera’s size on UI canvas.

This way is just shown on “Raw Image” object of UI. Because this UI object has fixed size which is balanced with other UI objects, the sub-camera’s image is appeared with fixed appropriate size on UI.
If you want to fix the image of sub-camera on UI, this is a good way. The balances with other UI parts are fixed. However if you want to show the image of sub-camera on one of some game object, you need to use different way.

[The steps to set sub-camera’s image on UI]

1. Create “Render Texture” in Project view

Firstly in Project view, add “Render Texture” like following image. It will transfer the image between Sub-camera and “Raw Image” of UI.


2. Create one more Camera as sub-camera

Add one new Camera as sub-camera in Hierarchy view. And attach the “Render Texture” just now created into ‘Target Texture’ of the sub-camera like following screen shot.


3. Create “Raw Image” for UI

Create “Raw Image” under UI in hierarchy view like this.

Attach the “Render Texture” on ‘Texture’ of the “Raw Image” like following.

That’s all, it’s very easy.

However if you set it one time, there are not so many opportunities to set this sub-camera again. Therefore it’s also easy to forget this way. I hope my this posting will help you every times.


[Original Japanese Site: http://blog.lab7.biz/archives/9745337.html]


Leave a Reply

Your email address will not be published. Required fields are marked *