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 newnew · Feb 15, 2011 at 11:23 AM · iosiphonetouch

simple TOUCH of a 3D object in iOS

Hi,

I tried to find out how to simply detect the touch of a 3D object with iOS. But I could not make it work on device.

Can someone please help me out:

Say there is a cube called "cube" and the user touches it on a iOS device.

How can catch this event??

thank you so much for your help!!!

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
6

Answer by Ryuuguu · Feb 27, 2011 at 04:14 AM

Putting together Jessy's answer in to a piece of code. The Update() and TapSelect() are put on any ONE Object in the scene. I put it ion my main game controller. The Selected goes on each object you to be able to select.

// Update is called once per frame void Update () { TapSelect(); }

void TapSelect() { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit ; if (Physics.Raycast (ray, out hit)) { hit.transform.SendMessage("Selected"); } } } }

 public void Selected(){
 Debug.Log("Selected",this); 

}

This is in c#. When the screen is tapped the TapSelect does a Raycast and if anything is hit it sends the Selected() message to the transform.

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 DannyB · Jun 15, 2012 at 02:23 PM 0
Share

This is great, thanks. I am using it to send a "On$$anonymous$$ouseDown" message ins$$anonymous$$d, so it serves as a transparent drop in replacement.

avatar image
2

Answer by Jessy · Feb 15, 2011 at 12:47 PM

Cast a ray from the position of a touch.

http://unity3d.com/support/documentation/ScriptReference/Collider.Raycast.html

That code uses ScreenPointToRay, which you should, but it also uses Input.mousePosition, which is not right on iOS. The thing you'll need to replace it with is a Touch.position. There are some examples in the documentation about how to code input for iOS:

http://unity3d.com/support/documentation/ScriptReference/Input.GetTouch.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

1 Person is following this question.

avatar image

Related Questions

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

iPhone touch events slowdown fps?!? 2 Answers

Magnifying Glass Unity iOS 0 Answers

Touch not working 1 Answer

Detect the swipe and add force respective to it? 3 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