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
4
Question by dberroa · Apr 20, 2013 at 10:52 PM · androidiphonetouchtouchscreenwindows8

How can I tell if the device I am on supports touch?

I ask this as I see there are platform dependent compilation that you can say, if iPhone or if Android, but what about the case with Windows 8 tablets and touchscreen computers?

I have a microsoft Surface pro that supports full Windows 8 Pro and has a touchscreen. If I made a desktop version of a game, the pro theoretically could support touch AND keyboard and mouse. If I restricted the touch code to just iPhone or Android, it would force the game to be keyboard and touch only.

I can't find anything like if (Input.SupportsTouch) {}.

How can I detect if a device supports touch generally without asking directly if it is of a specific type of device ie. iPhone?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
10

Answer by moobchunks · Feb 12, 2016 at 10:49 AM

Currently (it's been several years since OP asked), the Input class does have a ".touchSupported" and a ".multiTouchEnabled" (as well as others!). I would recommend using those in conjunction with the CrossPlatformInput standard asset to create and deploy a single code-base for your game across all your target platforms

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
7

Answer by trs9556 · May 04, 2013 at 04:20 AM

http://docs.unity3d.com/Documentation/ScriptReference/SystemInfo.html

 //check if our current system info equals a desktop
 if(SystemInfo.deviceType == DeviceType.Desktop){
     //we are on a desktop device, so don't use touch
     dontUseTouch = true;
 }
 //if it isn't a desktop, lets see if our device is a handheld device aka a mobile device
 else if(SystemInfo.deviceType == DeviceType.Handheld){
     //we are on a mobile device, so lets use touch input
     dontUseTouch = false;
 }

Should be able to figure it out from there.

Under SystemInfo there are a few other things that can help you out, like operating system/device name. Some googling will be required but all "windows 8 touch available" pcs might have something in common. If that is the case, for the example of windows 8 touch supported computers, you might be able to do a contains("thatCommonString") to enable/disable touch.

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
1

Answer by Adam-Buckner · May 02, 2013 at 11:59 AM

The first place to look is Platform Dependent Compilation: http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html

This is how you can have one code base and one project and deploy to many devices.

Platform Dependent Compilation also lets you check the version of Unity that's running, which can help when writing code that could be run on many different versions - say you were selling a package on the asset store and wanted to support both Unity 3.5 and Unity 4.1.

And example of how to use this code is here:

 void Update () {
     #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
         movement += new Vector3 (Input.GetAxis("XAxis"), Input.GetAxis("YAxis"), Input.GetAxis("ZAxis"));
     #else
         movement = Input.acceleration;
     #endif
     transform.Translate (movement, Space.World);
 
 }

This code takes Input.GetAxis from the Editor, Standalone builds and the Webplayer, otherwise, it uses acceleration from a mobile device... this could be touches or whatever code you'd like.

Other resources you could use could be "MultiTouchEnabled": http://docs.unity3d.com/Documentation/ScriptReference/Input-multiTouchEnabled.html

You may want to find a way that you don't have to poll that every frame, perhaps by enabling/disabling scripts on start based on this value?

Also you could experiment with polling for "TouchCount": file:///Applications/Unity/Documentation/ScriptReference/Input-touchCount.html

Have a quick scan of the Input class for more details on getting input from your devices: http://docs.unity3d.com/Documentation/ScriptReference/Input.html

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 Adam-Buckner ♦♦ · May 02, 2013 at 12:04 PM 0
Share

Please Note: When dealing with the Platform Dependent Compilation, UNITY_EDITOR is a separate enum! This makes it a different check from the other platforms. As such #if UNITY_EDITOR does not mean !UNITY_IPHON$$anonymous$$ As I said, these are two different checks, so you can have both #if UNITY_EDITOR and #if UNITY_IPHONE return true if you are in the editor and have the build target set for iOS devices.

If you are building specifically to, for argument's sake, Unity iOS, but want keyboard controls for testing, you would need to use something like:

 #if UNITY_EDITOR
     // Input$$anonymous$$anager Code for $$anonymous$$eyboards and $$anonymous$$ice
 #else
     // Touches and Acceleration from the iOS device
 #endif

If you are coding for mobiles, I believe you can say something like this:

 #if UNITY_EDITOR || (!UNITY_IPHONE && !UNITY_ANDROID)
     // Input$$anonymous$$anager Code for $$anonymous$$eyboards and $$anonymous$$ice
 #else
     // Touches and Acceleration from the iOS device
 #endif
avatar image dberroa · May 04, 2013 at 03:58 AM 0
Share

The problem with all of this is if you are using a desktop, using the UNITY_STANDALONE define would assume keyboard and mouse controls and not tell me if it supports touch.

I tried forcing mobile controls and it turns out that Windows Desktop doesn't seem to be picking up touches anyway on my Surface Pro. It seems as if Unity doesn't play nice with windows touch screens so my whole idea of asking this question doesn't really work anymore.

avatar image
0

Answer by dorpeleg · Apr 21, 2013 at 12:27 AM

I don't think it's currently possible.

either detect specific type of device or ask the user if he is using a touch device.

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 dberroa · Apr 28, 2013 at 08:37 PM 0
Share

I feel like even if you asked, you would still be doing if statement checks to see "if touch device" which would count against you at runtime.

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

15 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

Related Questions

What is the command to check whether player is touching the screen or not?? 1 Answer

Touch and release type of controll in Unity (Android). How to make it? 0 Answers

How to get position of touch on touch screen 1 Answer

ITouch multi touch with joystick problem 0 Answers

Processes two touches instead of one 0 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