Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 KKS21199 · Mar 05, 2017 at 10:31 AM · inputtouchmouseclick

Touch and MouseClick - One Game for Mobile and Desktop

Hi,

How can I get mouse clicks and touch position in a function when I am building for both Mobile and Desktop from the same build. From what I understand, mouse functions do work with mobile but it is better to use Touch.

So is there a way for me to make sure Touch and MouseClick both get's used without having to code it twice platform dependent? I wouldn't be requiring multi touch as far as I am concerned for now (if I do require then I will code once for mobile and once for desktop (use keyboard input on desktop)).

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 hexagonius · Mar 05, 2017 at 11:47 AM 0
Share

you can use Unity's built-in event system. it already reacts to mouse and touch depending on platform. you need:
- EventSystem
- Any Raycaster component (depends on use case)

avatar image KKS21199 hexagonius · Mar 05, 2017 at 02:20 PM 0
Share

I am already using the input functions of mouse. $$anonymous$$y question is whether or not it's reliable to work well on mobile side as well.

avatar image hexagonius KKS21199 · Mar 05, 2017 at 06:17 PM 0
Share

I think it's a little bit more expensive and unity does not recommend to use it on mobile, but depending on the user case and if course the profiler it's fine in most cases and reliable, yes.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OusedGames · Mar 06, 2017 at 12:36 AM

Hello, you can use Unity Plataform Dependent Complitation, and mark whick lines of codes will run on each plataform (Mobile, PC).

https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

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 OusedGames · Mar 06, 2017 at 12:38 AM 0
Share

Just to add, if I'm not wrong!! Functions like On$$anonymous$$ouseDown(), will run only on PC... I GUESS

avatar image
0

Answer by Jacho_Mendt · Mar 06, 2017 at 10:02 AM

A good alternative solution would be to implement your own wrapper to handle the input. This way, you wouldn't have to worry about error-prone code in your main scripts and it would be easier to debug.

You can have a setup method inside the wrapper that handles which function to call when, say, InputWrapper.Interaction(x,y) is called and either the screen touch or the mouse click has to be invoked. You could use Delegates and Events to decide what kind of Input to use, or a simple combination of if-else (or switches), but the basic idea is that it's this wrapper's job to decide which input method to use.

This way, you can also implement your own variants of different inputs (gamepads, joysticks, voice recognition...), the possibilities are endless.

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 ExtinctSpecie · Mar 07, 2017 at 10:47 AM

you can use interfaces and implement those methods they work in all platforms ive tried it https://docs.unity3d.com/ScriptReference/EventSystems.IBeginDragHandler.html

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

92 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 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 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 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 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

Touch a specific area on the screen 2 Answers

How to convert Touch Input To Mouse Input C# unity? 1 Answer

Differentiating inputs from mouse clicks and touches 1 Answer

Detecting a GameObject interaction in a portable fashion 1 Answer

Touching Falling Objects 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