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);
}
}
}
}
Use debug.log to see if the list is empty. If so, then check if the small circles have a collider.
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.
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.
Your answer
Follow this Question
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