Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by ElRobin · May 25, 2016 at 04:08 PM · scripting problem2d gametouch controls

In Unity 5.3, how do I detect a touch on a sprite in a 2D game?

I am making a game for pre-literate kids. I need to move to the next scene automatically when they have touched all the specific sprites in a scene. Because kids will poke at everything, I need to identify the touch on the sprite and, if it has not been touched before, increment a counter. Then, when all the correct sprites in the scene have been touched, I'll move to the next scene. But I have been unable to detect the touch on the sprite. Are there any example scripts?

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 FortisVenaliter · May 25, 2016 at 04:09 PM 0
Share

What have you tried so far?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ElRobin · May 26, 2016 at 01:00 PM

I used the button approach for another scene, but it means there is still a boundary around the sprite, so that would not be as desirable for this scene.

The second choice is my preferred one, but I can't seem to write a script that is correct that detects when the colliders are touched. An example script would be much appreciated.

The idea of disabling the script once the sprite is touched is great. Thanks.

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 Thajocoth · May 26, 2016 at 01:24 PM 0
Share

What I've been doing for all my buttons:

 void On$$anonymous$$ouseOver()
 {
     if (Input.Get$$anonymous$$ouseButtonDown(0))
     {
         //Do stuff
     }
 }

Technically, I think you're supposed to use GetTouch(), but it works...

avatar image imuniz Thajocoth · Sep 03, 2019 at 03:51 PM 0
Share

That was nice! Worked. This wouldn't work on mobile, right!?

avatar image
0

Answer by Thajocoth · May 25, 2016 at 05:09 PM

There are several ways to do this.

You could make them buttons that call a function when touched. If the function requires an ID, and each sprite passes a unique ID to the function, you could keep track of which IDs have already been touched.

You could add colliders to the sprites and a script that detect when the colliders are touched. The script could send a signal to a central script when it's touched and then disable itself, so further touch of that sprite would not be detected.

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

Identifying 3 GameObjects in contact with each other,Identifying and destroying 3 Game Objects with the same LayerName 0 Answers

How do I stop reading the first touch when using TouchPhase.Moved 0 Answers

[Question] Unity C# Set a Player Class and refence issue 0 Answers

Orbit an object around another based on touch input 0 Answers

How to get Y-Axis movement in 2D space shooter. 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