- Home /
Problem is not reproducible or outdated
How do you check if the object that you want to destroy with a click is the right object?
I have two balls: "A" and "B". How do you check if the object that you want to destroy with a click is the right object?
The idea is to indicate which object is to be destroyed and if you click in the wrong one, the information appeared that it is a bad object.
@polan31 Add a custom class to object that hold data public class Data : $$anonymous$$onoBehaviour { public bool AmIARightObject = false; }
Then use GetComponent()
Answer by anthot4 · May 09, 2018 at 10:18 AM
You could use an if statement to check the gameobject the raycast hit matches the name of the object you want destroyed.
If (Hit.gameobject.name == "BallA"){
Destroy(Hit.gameobject); } else{
// display text showing incorrect object selected. }
Follow this Question
Related Questions
OnMouseDown() Doesn't work 17 Answers
Right Mouse Click in Android 2 Answers
disable mmb and rmb raycast on ColorPicker 0 Answers
Fire missile to mouse click 1 Answer
Move at mouse click 0 Answers