- Home /
Get all objects within radius of mouse click.
Hello,
I am trying to get all the objects within a radius of a mouse click/touch.
I have had a look around, and I think I am to use Physics.OverLapSphere
Here is what I have so far:
public void Click1(object h)
{
RaycastHit hit = (RaycastHit)h;
GameObject hitGameObject = hit.collider.gameObject;
Debug.Log("HIT at '" + hit.point + "' RECEIVED IN '" + gameObject.name + "'");
Collider[] nearObjects = Physics.OverlapSphere(hit.point, 4F);
foreach (Collider object in nearObjects) {
if(object.tag == sticky)
Destroy(object.gameObject);
}
}
And here is the error: error CS1525: Unexpected symbol `object'
Any suggestions or a fix?
Answer by wijesijp · Apr 04, 2014 at 08:15 AM
object is a keyword. Use another variable name
Thanks, I thought it was that. But when I modified it to something else, it thru up another error.
Anyway, in the end I changed it and simplified the code and it works:
foreach (Collider Brick1 in nearObjects) {
print ("Hit " + Brick1);
Destroy(Brick1.gameObject);
}
And that works fine.
Thanks for the help
Your answer
![](https://koobas.hobune.stream/wayback/20220613141916im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unexpected symbol error 1 Answer
Distribute terrain in zones 3 Answers
4 errors in 1 script. Unexpected symbols and more, help please? 0 Answers
Unexpected symbol 'Flip' and 'else' 1 Answer