Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 F3RILLA · Jul 27, 2013 at 01:35 AM · guiaimcrosshair

Crosshair Aiming Issue, Simple, Yet Confusing.

Hey guys,

I am currently having an issue with a simple script I wrote, as GUI does not allow " yield WaitForSeconds", I had to create two GameObjects with two different crosshairs. One of the crosshair is used for shooting from the hip (NormalCrosshair) and the other allow the player to aim at an object and shoot (FocusCrosshair).

The problem is, whenever I am aiming (FocusCrosshair) and press the shoot button (Fire1), the other crosshair (NormalCrosshair)is shown on the screen along with the other aim(FocusCrosshair).

Is there any possibilities of using left mouse key (Fire1) to shoot from the hip and when the player is aiming with the right mouse key (Key1) and press the left mouse key (Fire1), it won't show the other crosshair (NormalCrosshair).

Thanks everyone, the script can be found below:

P.s. Sorry for bad english, been working on this project for the past 7 hours and it's 2:33am.

 #pragma strict
 
 var NormalCrosshair : GameObject; //Normal Crosshair
 var FocusCrosshair : GameObject; //Aim Crosshair
 
 function Start()
 {    
     //On-load Disable GameObject
     NormalCrosshair.active = false;
     FocusCrosshair.active = false;
 }
 
 
 function Update()
 {
 
     if(Input.GetButtonDown("Fire1"))
     {
         //Shoot without Aiming but still show a Crosshair (See NormalCrosshairExecute function)
         NormalCrosshairExecute();
         Debug.Log("Normal Crosshair Executed");    
     }
         
     if(Input.GetButtonDown("Fire2"))
     {
         //Aim Activated with Right Mouse Click
         FocusCrosshair.active = true;
         Debug.Log("Focus Crosshair Active");                
     } 
     else if (Input.GetButtonUp("Fire2"))
     {
         //Aim Deactivated on Button Release
         FocusCrosshair.active = false;
         Debug.Log("Focus Crosshair In-active");
     }
 
 }
 
 
 function NormalCrosshairExecute()
 {
     //Enable Normal Crosshair
     NormalCrosshair.active = true;
     //Wait for Seconds
     yield WaitForSeconds (0.03);
     //Disable Normal Crosshair
     NormalCrosshair.active = false;        
 }

 
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
2
Best Answer

Answer by Jamora · Jul 27, 2013 at 02:56 AM

Have NormalCrosshairExecute execute only if the other crosshair is not shown.

 if(!FocusCrosshair.active)
    NormalCrosshairExecute();
Comment
Add comment · Show 1 · 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 F3RILLA · Jul 27, 2013 at 01:01 PM 0
Share

Thanks a lot, that fixed the problem :)

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.

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

spaceship aim 1 Answer

Dealing with multiple crosshairs 0 Answers

Simple GUI In game 1 Answer

Crosshairs Gui don't stay the same how to fix??? 1 Answer

Move cursor/crosshair based on keyboard input 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