• 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
0
Question by RuSchoeman · Oct 31, 2013 at 05:27 PM · adsrendertexturescopesniperaimdownsights

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

Hello Community.

Recently I started working on a FPS assassination video game. I created a scope that works with a secondary camera at the front of my scope, which targets a plane and renders with a render texture.

Hipfire

Aim down sights

This issue I am facing, is I am having trouble overlaying a texture of the scope's crosshair (the + in a sniper's scope). I want it to display over the render texture, while still being as accurate as it can be. Please help, as I am stuck with this issue and can't continue my project until the current issue is fixed.

The code I am using for my scope to go into the ADS mode , is as follows..

 #pragma strict
 var defaultFOV : int = 0;
 var fovSpeed : int = 0;
 var fovIn : int = 0;
 
 var gunAim : boolean = false;
 var playerCam : GameObject;
 
 var gunModel : GameObject;
 var scopeInAnim : String;
 var scopeOutAnim : String;
 
 function Start () {
     defaultFOV = playerCam.camera.fieldOfView;
 }
 
 function Update () {
     if(Input.GetMouseButtonDown(1)){
         animation.Play(scopeInAnim);
         gunAim = true;
     }
     if(Input.GetMouseButtonUp(1)){
         animation.Play(scopeOutAnim);
         gunAim = false;
     }
     
     if(gunAim){
         playerCam.camera.fieldOfView = Mathf.Lerp(playerCam.camera.fieldOfView, fovIn, fovSpeed * Time.deltaTime);
     }
     
     if(!gunAim){
         playerCam.camera.fieldOfView = Mathf.Lerp(playerCam.camera.fieldOfView, defaultFOV, fovSpeed * Time.deltaTime);
     }
 }



It's a javascipt code, btw.

Please help, thanks in regards. -RuSchoeman

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
1

Answer by Cherno · Oct 31, 2013 at 08:46 PM

Why not use GUI.DrawTexture inside OnGUI() ?

Comment
Add comment · Show 2 · 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 RuSchoeman · Nov 01, 2013 at 07:01 AM 0
Share

If it is not too much of an hassle, could you explain it in more detail to me please? Like, where do I attach the script, and how do I draw it? Sorry for asking.

avatar image ejpaari · Nov 01, 2013 at 07:50 AM 0
Share

Something like this

function OnGUI() { if(gunAim){ GUI.DrawTexture(Rect(left,top,width,height), scopeTexture); } }

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does the canvas image, go, show up as soon as I press Mouse1? 1 Answer

Sniper scope zoom if crosshair is not in the middle of the screen 2 Answers

How to make Sniper Scope with Range pointer Digit as Sniper 3d assassian Game 1 Answer

how to make a 2d sniper game. 1 Answer

How do I make a camera's view a texture(screen) 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