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 newtondhande · Jun 13, 2015 at 07:06 PM · androidunity 5gameobjecttouch

How to select gameobjects on android by touching on them?

I am trying to create match 3 game like candy crush while learning unity. How can i store references of two gameobjects(object) which are to be swapped on android device? On computer it is working fine i did it using onMouseDown() on gameobject and having two gameobject references to store selected objects in gamecontroller script. Thanks for any help and suggestion and sorry for bad English.

Comment
Add comment · Show 2
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 newtondhande · Jun 14, 2015 at 01:16 PM 0
Share

Thanks Guppie1337 I will check this out. Does this works with 3D objects? Can you explain ScreenToWorldPoint part please i am not getting it.

avatar image Guppie1337 · Jun 14, 2015 at 02:49 PM 0
Share

No worries! Basically what ScreenToWorldPoint does is it takes the position of your screen and converts it into a world point. World points (The scene) work off of coordinates like (1,5). Screen points I believe either work off of pixel points (essentially the same thing but for the screen) or viewport points (which are any value for x and y from 0 to 1). Here it is in the Scripting API - ScreenToWorldPoint.

To answer your question about if this works in 3D. From what I know, yes. The difference is that you wouldn't convert it to a vector 2 but ins$$anonymous$$d use all 3 original coordinates. The whole depth concept tends to throw me off though.

If this answers your question, please tick it :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Guppie1337 · Jun 14, 2015 at 12:40 PM

If you are asking just how to touch these objects:

 if (Input.touchCount == 1)
    {
      Vector3 worldPos =       Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
       Vector2 touchPos = new Vector2(worldPos.x, worldPos.y);
 
         if (collider2D == Physics2D.OverlapPoint(touchPos))
         {
            //Do stuff with it here like check gameObject tags and such.
         }
     }
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 Arigarasuthan · Apr 12, 2018 at 11:33 AM 1
Share

what is collider2D?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Game Object On Touch Event on Android-iPhone 2D 4 Answers

Select 2 out of 3 gameobject before doing something. 0 Answers

Touch.deltaPosition giving jerky movement on Android in Unity 5 2 Answers

How to destroy a particular clone on touch/mouse? 1 Answer

Input.GetTouch(0).deltaPosition.x returns 0 sometimes 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