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 Blink · Oct 13, 2012 at 11:04 AM · guitexturecrosshair

Crosshairs change when sprinting?

This script adds a crosshair texture in the middle of my screen and then hides it if the right mouse button is being held down. Im trying to change the crosshair when the player is sprinting, but Im not sure what to put in my update, can anyone help me out?

 var crosshairTexture : Texture2D;
 var sprintCrosshairTexture : Texture2D;
 var position : Rect;
 var rightClick : boolean = true;
 
  function Start(){
 
 
 
         position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
 
 }
 
 
 
 function Update() {
 
 
 
 if(Input.GetButtonDown("left shift")){
 
   //texture change to sprint texture
 
 }
 
 
 
 if(Input.GetButtonUp("left shift")){
 
   //texture change back to normal texture
 
 }
 
   
 
 
 
 if(Input.GetMouseButtonDown(1)){
 
       rightClick = false;
 
   }
 
   
 
   if(Input.GetMouseButtonUp(1)){
 
       rightClick = true;
 
   }
 
 }
 
 
 
 
 
 function OnGUI(){
 
 if(rightClick){
 
     GUI.DrawTexture(position, crosshairTexture);    
 
 }
 
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Griffo · Oct 13, 2012 at 12:48 PM

OK try this ..

     var crosshairTextureBig : Texture2D;
     var crosshairTexture : Texture2D;
     var sprintCrosshairTexture : Texture2D;
     var position1 : Rect;
     var position2 : Rect;
     var rightClick : boolean = true;
     var shiftButton : boolean = fasle;
     
      function Start(){
     
     
     
             position1 = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
     
             position2 = Rect( ( Screen.width - crosshairTextureBig.width ) / 2, ( Screen.height - crosshairTextureBig.height ) / 2, crosshairTextureBig.width, crosshairTextureBig.height );
     
     }
     
     
     
     function Update() {
     
     
     
     if(Input.GetButtonDown("left shift")){
     
       shiftButton = true;
     
     }
     
     
     
     if(Input.GetButtonUp("left shift")){
     
       shiftButton = false;
     
     }
     
     
     
     
     
     if(Input.GetMouseButtonDown(1)){
     
           rightClick = false;
     
       }
     
     
     
       if(Input.GetMouseButtonUp(1)){
     
           rightClick = true;
     
       }
     
     }
     
     
     
     
     
     function OnGUI(){
 
 if(rightClick){
 
     GUI.DrawTexture(position1, crosshairTexture);    
     }
 
 if(shiftButton){
 
 GUI.DrawTexture(position2, crosshairTextureBig);
 rightClick = false;
     }
 
 if(!shiftButton){
 
 GUI.DrawTexture(position1, crosshairTexture); 
     }
 }
Comment
Add comment · Show 6 · 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 Blink · Oct 13, 2012 at 12:50 PM 0
Share

I get errors saying unknown identifier position1, position2 and position3 can you help please?

avatar image Griffo · Oct 13, 2012 at 12:52 PM 0
Share

position 3 ? ... Try the amended code above.

avatar image Blink · Oct 13, 2012 at 12:54 PM 0
Share

oh there's no position3, ive just added a few more variables and I solved it. But when I hold the right mouse button my crosshairs still show and ins$$anonymous$$d of changing the crosshair when the left shift is held down it overlaps both of the textures.

avatar image Blink · Oct 13, 2012 at 01:02 PM 0
Share

It still shows when ai$$anonymous$$g in and overlaps when sprinting.

avatar image Griffo · Oct 13, 2012 at 02:15 PM 0
Share

Edited .. should work now.

Show more comments
avatar image
-1

Answer by theringyt · Oct 14, 2012 at 08:10 PM

Please give me the sprint code :)

Comment
Add comment · 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
0

Answer by Griffo · Oct 13, 2012 at 12:07 PM

Something like

 function Update() {
 
 if(Input.GetButtonDown("left shift")){
 
    position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width * 2, crosshairTexture.height * 2 );
 
 }
 
 if(Input.GetButtonUp("left shift")){
 
    position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
 
 }
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 Griffo · Oct 13, 2012 at 12:09 PM 0
Share

Or ..

 crosshairTexture.width + 10, crosshairTexture.height + 10
avatar image Blink · Oct 22, 2012 at 05:07 PM 0
Share

Ins$$anonymous$$d of changing the crosshair when scripting is there a way to hide it as well as when ai$$anonymous$$g in?

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

11 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

Related Questions

Make a crosshair turn red when over an enemy 1 Answer

GUITexture scaling with aspect ratio? 1 Answer

change crosshair texture by checking switch statement? 0 Answers

How can i show number of lives as image during gameplay 1 Answer

Aspect ratio keeping guitexture scaling 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