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
2
Question by MikezNesh · Jan 14, 2011 at 05:27 AM · disappearcrosshair

Crosshair disappears?

I have a script for my crosshair texture to follow my mouse. And when I build my game it works. But the problem is, after I hit space without moving my mouse the crosshair disappears. After I move the cursor around a bit it re-appears. How can I get it to show without disappearing?

SCRIPT:

var crosshairTexture : Texture2D;

function Start() { Screen.showCursor = false; }

function OnGUI () { var mousePos = Event.current.mousePosition; GUI.DrawTexture( Rect( mousePos.x - (crosshairTexture.width/2), mousePos.y - (crosshairTexture.height/2), crosshairTexture.width, crosshairTexture.height), crosshairTexture); }

Comment
Add comment · Show 3
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 Pat · Jan 18, 2011 at 04:56 PM 0
Share

Do you have any other code that looks for keyboard input. Looking at this code it seems like everything should be fine, which makes me think the problem is somewhere else in your code.

avatar image MikezNesh · Jan 23, 2011 at 01:41 AM 0
Share

Possibly, will double check.

avatar image MikezNesh · Jan 23, 2011 at 09:22 PM 0
Share

After taking a closer look. The crosshair doesn't disappear. But it moves to (0,0). I looked at all my scripts. None should do that. Any other reasons that this might happen?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by 5parrowhawk_legacy · Jan 18, 2011 at 04:48 AM

Wild guess: hitting a key might fire an event with a null mouse position, which causes your cursor to be drawn offscreen or not at all. Try using Input.mousePosition instead of Event.current.mousePosition and see if that helps. (IIRC you may have to reverse the Y axis, but I could be wrong on that one.)

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 MikezNesh · Jan 23, 2011 at 09:13 PM 0
Share

what would the code for nulling the mouse position look like?

avatar image 5parrowhawk_legacy · Jan 24, 2011 at 06:12 AM 0
Share

Huh? No, what I'm saying is that hitting a key might fire an event which has a mouse position of 0,0. So Event.current.mousePosition would be 0,0, and your cursor is set to position 0,0 until a mouse event fires (which would reset the cursor). I haven't tested this so I can't confirm it, but it sure sounds like that's what's happening. Have you tried replacing Event.current.mousePosition with Input.mousePosition yet?

avatar image
0

Answer by JoeStrout · Jan 16, 2011 at 03:03 PM

I realize this isn't much help, but it is at least a data point: I tried your script on my machine, and the problem isn't occurring here. I'm using Unity 3.1.0f4 on Mac OS X 10.6.6.

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

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Make a crosshair turn red when over an enemy 1 Answer

Make a Cursor Disappear? 1 Answer

C# OR Java- Multiplayer Shoot Sound 0 Answers

How to import the object from server to unity 2 Answers


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