Before updating to Windows 10 you may need to return your Pro license. More information here

Sniper zoom

i made a sniper, i can right click and it zooms in, then i let go and it zooms out


but i want it to have like a screen where only that zooms in more like


i think i have to have a plane, and then add something to that plane that shows an image from something else

more ▼

asked Oct 17, 2011 at 10:29 PM

avatar image

18 11 14 18

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You must use a second camera childed to the weapon to show the zoomed image (set Field of View to a small angle - 15 to 30 - to zoom).

If you have Pro, you can assign a RenderTexture to this camera's targetTexture property, what will make the second camera render to this texture. The RenderTexture can be assigned to a new material, and this material used to "paint" the scope (that's probably the way it's done in the linked video).

If you don't have Pro, you can set the second camera's pixelRect property to a small square in the center of the screen (set the camera's depth to 1 to draw over the main camera) and draw the scope body over it with GUI.DrawTexture:

alt text

In this case, the scope body is a 308x308 PNG texture with transparency (see credit and reference at the page foot), and the center area can hold a camera image of 196x196 pixels. You can bring the weapon to the aim position and enable the camera and texture drawing with something like this:

 var texScope: Texture;  // drag the scope image here
 var scopeCam: Camera;   // drag the scope camera here
 var rCamera = Rect(0, 0, 196, 196);
 var rScope = Rect(0, 0, 308, 308);
 var enableAim: boolean = false; // set enableAim to true to aim
 function OnGUI(){
   if (enableAim){
     rCamera.x = (Screen.width - rCamera.width)/2; // center rCamera
     rCamera.y = (Screen.height - rCamera.height)/2;
     rScope.x = (Screen.width - rScope.width)/2; // center rScope
     rScope.y = (Screen.height - rScope.height)/2;
     scopeCam.pixelRect = rCamera;
     scopeCam.enabled = true;
     GUI.DrawTexture(rScope, texScope, ScaleMode.ScaleToFit, true, 0);
   else {
     scopeCam.enabled = false;
 function Update(){
   enableAim = Input.GetMouseButton(1); // aim while the right mouse button is pressed

CREDIT/REFERENCE: The scope image above was captured from the game EliteSquad (2nd linked video), created by leonardotry, and edited to make transparent the undesired areas. You can download it for testing purposes - (click here to download the image).

more ▼

answered Oct 18, 2011 at 12:33 AM

avatar image

61.5k 57 212 361

"thanks but this is for pixelrect, could you show me how to do the rendertexture, ive been looking for it for a while (i have pro)":

Well, I don't have Pro, so I've never tested Render Textures, but the docs give a recipe (here) that I adapted a little to your case:

1- Create a new Render Texture asset using Assets->Create->Render Texture;

2- Create the scope camera and child it to the weapon;

3- Assign the Render Texture to the Target Texture of the scope Camera;

4- Create a quad and child it to the weapon (this will be the scope lens);

5- Drag the Render Texture onto it to create a Material that uses the render texture.

6- Click Play: the scope camera should draw on the quad whatever it sees.

Hope this works fine (even because I can't help further without a Pro).

Oct 19, 2011 at 11:21 AM aldonaletto

The script works beautiful many thanks!

Jan 29, 2013 at 04:02 PM shrooster

wow didn't know it can be that easy, ... thanks @aldonaletto +1

Nov 10, 2013 at 11:42 AM sdgd
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 17, 2011 at 10:29 PM

Seen: 8837 times

Last Updated: Nov 10, 2013 at 04:44 PM