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
0
Question by Raukor · Sep 12, 2015 at 01:27 AM · touch controls

Unity2D Deleting objects around a point touched.

In my program i have a seperate script which spawns small circles on the screen. I want this script to be able to remove the circles that are near where you are touching the screen. Currently, the objects are non responsive.

Edit: Posted updated script. I'm getting coordinates from the touch controls, but I can't get the Collider2D[] to fill, keeps returning a list length of 0. The objects do have colliders on them.

 using UnityEngine;
 using System.Collections.Generic;
 
 public class InputControls : MonoBehaviour {
 
     Touch myTouch = new Touch();
     Vector2 myPosition = new Vector2();
 
     void Update () 
     {
         if (Input.touchCount > 0)
         {
             myTouch = Input.touches[0]; 
             myPosition = myTouch.position; 
 
             Collider2D[] cleaningMoss = Physics2D.OverlapCircleAll(myPosition, 2f);
 
             Debug.Log(cleaningMoss.Length); //this is returning 0
 
             for (int i = 0; i < cleaningMoss.Length; i++)
             {
                 Destroy (cleaningMoss[i].gameObject);
             }
 
         }
 
     }
 }

Comment
Add comment · Show 3
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 Rostam24 · Sep 12, 2015 at 03:38 PM 0
Share

Use debug.log to see if the list is empty. If so, then check if the small circles have a collider.

avatar image hexagonius · Sep 12, 2015 at 08:33 PM 0
Share

Use an array for cleaning$$anonymous$$oss and assign the result of the overlap to it. there is no need for a list, the conversion is not necessary. oh the for loop, iterate it cleaning$$anonymous$$oss.Lenght times and not 99. First try without layermask, if that works 512 is wrong.If it still doesn't, the circles in the scene do not have colliders on them.

avatar image Raukor hexagonius · Sep 13, 2015 at 01:34 AM 0
Share

I won't be able to work on changes until tomorrow, but 512 should be right, i have tried it with out a mask and it still didn't work, i have another script that is using the layer above that with 256 and that seems to be working. On that same note, the colliders on the circles do exist and seem to be working, the same script that i have running on the other layer, was interacting with the circles colliders before i masked it. That said, ill clean up the code, switch over to an array and see where that puts me.

0 Replies

· Add your reply
  • Sort: 

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

29 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 avatar image avatar image avatar image avatar image avatar image 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 To Move A Ball Using Touch Input? 0 Answers

Function OnTouchDown? 2 Answers

Detect touch input 1 Answer

How do you climb ladders using touch controls? 0 Answers

Andriod Touch Controls Keycode Input 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