- Home /
How to destroy the cube which I selected with the arrow key
The cube is the green one. I wanted for instance press the left arrow and destroy only the left cube without destroying the others around it.
Physics.Linecast() is one possible solution where you use the Transform.right vector for the check. You will need to use Raycast layers or remove the collider from the green cube to make it work.
Answer by MountDoomTeam · Feb 15, 2013 at 05:53 AM
have a look at script to select object with mouse using mouse button, and then 3 lines to say when you press D, the selectedCollider.GameObject is destroyed.
Answer by hherzog · Feb 18, 2013 at 12:57 AM
I did it another way: I created 4 cubes as children and used "IsTrigger." When I press the arrow matched the corresponding cube changes "IsTrigger" to "true". Works like a charm. : D
Your answer
Follow this Question
Related Questions
overlapsphere to destroy NPCs on exit 1 Answer
Best collision detection method? 2 Answers
How to setup character Collisions? 2 Answers