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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Hedayk · Apr 13, 2012 at 06:56 PM · iosbuttoniphonecontrolstouchscreen

Mapping iOS touchscreen as simple buttons

I am having a really tough time figuring out how to map a touch on the screen to do certain things.

I figured out how to make the entire touchscreen on an iPhone act as the jump button, but I would like to split up the screen into different sections:

Left half: Jump Right Top half: Accelerate Right Bottom half: Deccelerate

I wish I had some code already implemented that were giving me errors but I haven't come across what I'm trying to look for at all. I don't need to render any GUI and I need this function to occur during function Update() { }.

If anyone could at least point me in the right direction that would be muuuuch appreciated! I apologize for the lack of info but I'm really not getting anywhere yet after a couple hours of researching and messing with scripts.

Thank you so much for reading and if you have any questions before you come up with anything feel free to ask anything.

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

2 Replies

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

Answer by rutter · Apr 13, 2012 at 07:14 PM

`Input.touches` will give you a set of `Touch` structures representing all current touches. Each touch has a `position` field, along with some other very useful data. Read up a bit on it.

You can compare a touch position against `Screen.width` and `Screen.height` to determine where on the screen the finger is touching. Left half, right half, and so on should be very easy to calculate with this method.

If you need to figure out what in the world your player is touching, you could convert the touch to a Vector3 and use `Camera.ScreenPointToRay()` and `Physics.Raycast()`. This is potentially useful for clicking on "button" objects which you can actually represent using in-world colliders, or for picking other game objects directly.

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 Hedayk · Apr 13, 2012 at 07:18 PM 1
Share

Ah thanks that does help. No need to translate the touch to a 3d environment with raycasts! Just was trying to find some simple screen location based touches. Thanks again I'll look into these.

avatar image
0

Answer by winresh · Apr 14, 2012 at 06:25 PM

hello @rutter can i ask you a question..?

Is there a way to test a android/ios game without a device...

I hope you will reply..

thanks

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI.Button lags on iPhone 0 Answers

RPG style controls for iOS/Android 0 Answers

How to change my game into an ios game 1 Answer

Does the Iphone X have a different touchscreen? 0 Answers

On iOS, how do I fade out music when the user presses the home button? 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