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 I Am The Minion · Apr 05, 2013 at 03:27 PM · instantiatetaptouchphasedouble

Unwanted multiple Taps

My script instantiates a prefab at point of click or touch, every time it is clicked or touched. The problem I am having, is that more than one instance of the prefab is created with every single touch. I managed to solve it for the click version.

Initially, i did this:

 if(Input.GetMouseButtonDown (0))
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     Debug.DrawRay (ray.origin, ray.direction * 1000, Color.yellow);
     RaycastHit hit;
     if(Physics.Raycast(ray, out hit, 1000))
     {
         GameObject newBomb = (GameObject)Instantiate (bomb, hit.point, Quaternion.identity);
     bombOrder.Add (newBomb);
     }
 }
 if(Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Began)
 {
     //place bomb at touch location
     Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
     RaycastHit hit;
     if(Physics.Raycast (ray, out hit, 1000))
     {
         GameObject newBomb = (GameObject)Instantiate (bomb, hit.point, Quaternion.identity);
     //add bomb to list
     bombOrder.Add (newBomb);
     }
 }

When I changed GetMouseButtonDown to GetMouseButtonUp, that solved the problem. I tried the same approach on the touch-version by changing TouchPhase.Began to TouchPhase.Ended. No change, unfortunately. I'm still getting at least 2 instances per touch. Could it be a performance issue? I'm thinking if there is a slight lag-spike on instantiation, it might read multiple touches.

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 Owen-Reynolds · Apr 05, 2013 at 03:59 PM 0
Share

Is this maybe in FixedUpdate (ins$$anonymous$$d of Update?)

It wouldn't have anything to do with Instantiate, since the IF isn't checking it. I'd feel better with #if UNITY_IOS around parts, but that probably won't matter.

Get$$anonymous$$ouseDown should be working. I'd set up a quick test scene with that to try to find a structural problem (script on two things? ... )

avatar image I Am The Minion · Apr 05, 2013 at 04:28 PM 0
Share

Changing from FixedUpdate() to Update() did reduce the number of unwanted instances, but did not remove them entirely

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by I Am The Minion · Apr 05, 2013 at 04:48 PM

Durrr It just hit me. Unity translates touch to click. Everytime I touch the game, it does what it says under both the click AND touch conditions. Thats why I'm getting 2 instances. Excluding the click query should fix this problem.

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 LyanApps · Apr 09, 2013 at 07:20 PM 0
Share

you could also do either an else if or an or

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make a double-tap system for dashing 7 Answers

Destroy A Certain Instantiate On Tap Help? 1 Answer

Checking if object intersects? 1 Answer

Taps are not detected on mobile 1 Answer

Diagonal movement causing player to run (counting as a second tap for double tap running) 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