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
1
Question by DaveA · Sep 01, 2010 at 09:55 PM · iphonemousetouchclick

How to get 'object touched' (Non-GUI) on iPhone?

Please forgive if asked/answered, so many posts!

I have some in-scene (NOT GUI!) objects I need to know if the user touches (clicks).

In my Win/Mac version I have a collider on my object which repsonds to OnMouseDown

What's the equivalent for iPhone, if any? I've seen the GUI solutions, not what I need.

Comment
Add comment · Show 1
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 · Sep 02, 2010 at 04:01 AM 0
Share

Is this question different to http://answers.unity3d.com/questions/5941/is-it-possible-to-touch-3d-object-for-using-unity-in-iphone ? It might well be - I'm unfamiliar with Unity iPhone - but it shows up as the top of the related question list, and sounds similar!

3 Replies

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

Answer by DaveA · Sep 02, 2010 at 03:54 AM

I wanted this to be a 'drop in' replacement for my mousehandler, so here's the script I put on my prefab:

function Update() {

if (Input.GetMouseButtonDown(0)) // check for left-mouse
{
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
    if (collider && collider.Raycast (ray, hit, 100.0))
    {
        OnMouseDown();
    }
}

}

function OnMouseDown() { blah blah }

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 jtbentley · Sep 01, 2010 at 11:17 PM

var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit;

if (Physics.Raycast (ray, hit, 200)) { var objecthit:Transform = hit.transform as Transform;

 // What are you hitting?
 if (hit.collider.tag == "3DButton") doStuff()
  }

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 DaveA · Sep 02, 2010 at 03:50 AM 0
Share

Pretty close, thanks

avatar image
0

Answer by qJake · Sep 02, 2010 at 01:36 AM

You can also use OnMouseDown(), which is easier, but the object has to have a collider, I believe.

Comment
Add comment · Show 3 · 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 DaveA · Sep 02, 2010 at 03:50 AM 0
Share

No, not available on iPhone (2.6)

avatar image qJake · Sep 02, 2010 at 07:53 AM 0
Share

Are you sure? I've used On$$anonymous$$ouseDown() on Android... perhaps it's a 3.0-only feature.

avatar image DaveA · Sep 04, 2010 at 01:06 AM 0
Share

That may be. I'm not using 3.0 'seriously' yet as so many things are broken for me.

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

Replace Touch commands with mouse events 2 Answers

Click Drag not working on iphone 2 Answers

How can I make the character move to clicked position without allowing the user to drag? 1 Answer

Destroy on touch for iphone 1 Answer

Right Mouse Click in Android 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