• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ibayibay1 · Oct 17, 2011 at 10:29 PM · zoomscopesniperoafa

Sniper zoom

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

http://youtu.be/20Y1zJ-x-eo

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

http://youtu.be/3eYEOS4IHW8

i t$$anonymous$$nk i have to have a plane, and then add somet$$anonymous$$ng to that plane that shows an image from somet$$anonymous$$ng else

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by aldonaletto · Oct 18, 2011 at 12:33 AM

You must use a second camera c$$anonymous$$lded 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 t$$anonymous$$s camera's targetTexture property, what will make the second camera render to t$$anonymous$$s texture. The RenderTexture can be assigned to a new material, and t$$anonymous$$s 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 t$$anonymous$$s 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 somet$$anonymous$$ng like t$$anonymous$$s:

 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 w$$anonymous$$le 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).

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aldonaletto · Oct 19, 2011 at 11:21 AM 5
Share
avatar image shrooster · Jan 29, 2013 at 04:02 PM 0
Share
avatar image sdgd · Nov 10, 2013 at 11:42 AM 0
Share

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sniper scope zoom variances 0 Answers

Sniper Zooming 2 Answers

Sniper Scope with zoom 1 Answer

Sniper Zoom Problem 1 Answer

Sniper Scope zooms in, but I don't know how to display the crosshair 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges