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 Moix · Nov 13, 2013 at 04:52 PM · mousecursorclick objects

how to simulate mouse click with fake cursor

I'm making a 2 player game with Wii controls. Of course for the second player I cannot use the mouse cursor.

For the cursors I will probably use a GUI texture, but I don't know how to let the second user click on gui elements, or 3d elements.

For the 3d elements I thought about raytracing from the x,y coordinates and see which object it collides with, but it would be easeer if I just could simulate clicks all over the game in 3d an gui elements too.

So how can I do that?

Comment
Add comment · Show 4
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 Starwalker · Nov 13, 2013 at 07:13 PM 1
Share

To click on 3d objects to screen use this:

Camera class, Screen to viewport

or

Camera class, World to Screenpoint

The above 2 are used for interaction of 3d elements via viewport/screen space and not involving a ray cast to detect.

All GUI button type elements will come with a bool return value:

Gui Button

So once you have identified the area you want to look at, or interacted with the 3d object, you can use the GUI to fire an event to do stuff.

A little costly but accurate way is Physics.RayCast method for identification.

On$$anonymous$$ouseOver() is also an event which gets fired if the script is attached to the object in question/monitored.

Hope it helps.

avatar image Moix · Nov 13, 2013 at 11:43 PM 0
Share

Thanks

I understand how to get the coordinates from viewport to 3d world. But how can I know if those coordinates intersect with a 3d object without using a ray cast?

Also, you say I can attach a script to make a mouseover event, but I will not be using a mouse cursor... I don't really understand what you mean there.

avatar image Starwalker · Nov 14, 2013 at 12:47 AM 0
Share

The screen based detection solution requires you to atleast have a On$$anonymous$$ouseOver() function in the script attached to the object which is to be $$anonymous$$ouse-overed, this is just to fire an event which you can use to update your GUI.

Independently speaking, the Physics.Raycast is what is normally used to detect the hit. Physics.Raycast is put on the camera usually because the center of the camera is the center of the screen when it raycast's. Now if you have many object's close to each other, a raycast will pass through them and you'll go into a proximity issue, that means, a ray cast of magnitude 100 can pass thru 2 spheres of diameter 50, and it will return which ever it hits 1st or might return the 2nd (whichever is closer to the camera), which is un predictable.

So if your scene has no close proximity objects then go with raycast, it should be fine. If you have close proximity, go with "On$$anonymous$$ouseOver()" solution. because $$anonymous$$ouseOver will give accuracy over -What-you-See- vs what you cast-into.

Hope that gives you some insight of how and why both are used.

avatar image Benproductions1 · Nov 14, 2013 at 10:10 AM 0
Share

@Starwalker. The On$$anonymous$$ouseOver "event" is actually just a Physics.Raycast call, so neither are "what you see". Physics.Raycast is sorted via hit distance not object distance, so the only problem you can encounter is when an object is cut off by the near clip plane. Otherwise there are no inaccuracies.

0 Replies

· Add your reply
  • Sort: 

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

19 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 avatar image avatar image avatar image

Related Questions

Cursor Disappears In Scene View When Play Mode Is On 2 Answers

Game runs on one screen, cursor wanders onto other screens? 0 Answers

error CS8025: Parsing error 1 Answer

How to make something happen when mouse on side of screen? 1 Answer

Cursor appearance change when mouse over a GUI button 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