Using the render texture to realize the game's small radar effect (camera split screen)

Source: Internet
Author: User
Tags radar

Recently the game bull is holding an activity, is to make this effect:

Title: Realize the game split screen effect

Requirements:
1, split the screen, and the split line irregular (that is, non-horizontal or vertical);
2, each screen can be operated alone (move, zoom), operation refers to the overall operation of the screen;
3, left (or upper) cube clockwise rotation, right (or down) cube counterclockwise rotation;

At first I thought that I had to use the most unfamiliar shader, a little afraid, then carefully think, this is not the same as the radar effect?

Then go ahead and do an effect to play.

The simple principle is to get two cameras, a sub-object as player, and put it behind the player, with the player,

When the third person camera, this is a master camera, without setting anything. The second camera also acts as the player's self-object,

And put it on the top of the player's head as a top-down camera so the camera sees a radar-like effect.

But I'm not going to draw the camera directly to the screen, after all, the camera can only be square, if you put it directly on the screen,

does not achieve the effects of the various shapes we want, all I first project the contents of the camera onto a "Render Texture" body,

Right-click a new "Render Texture" in Project view

This render Textur is then cropped to the shape I want by Ugui and then projected onto the screen as a GUI.

The following are the specific practices:

First set the mask mask, specifically what shape your own PS draw a

Then add a rawimage from the object to the mask and display the render texture to the sub-object,

Now that it's over, add a piece of control code to the player and you can make a simple third-person game.

usingUnityengine;usingSystem.Collections; Public classPlayercontroller:monobehaviour { Public floatWalkspeed =2.0f;  Public floatRotatespeed =3.0f; PrivateCharactercontroller Controller; //Use this for initialization    voidStart () {Controller= getcomponent<charactercontroller>(); if(Controller = =NULL) {Debug.logerror ("Charactercontroller cound not being found"); }    }        //Update is called once per frame    voidUpdate () {varx = Input.getaxis ("Horizontal"); varz = Input.getaxis ("Vertical"); Controller. Simplemove (Transform.forward* Z * walkspeed *time.time); Transform. Rotate (0, X * rotatespeed,0); }}

To summarize:

In fact, the principle of irregular-shaped camera split screen is to first draw the contents of the camera to a picture,

Then cut out a certain shape by Ugui the mask effect, and then put the picture on the cropped picture,

It shows the contents of the cropped camera.

Finally attach the source code:

Click I download

Using the render texture to realize the game's small radar effect (camera split screen)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.