- Home /
Is it possible to destroy the component "BoxCollider" of the object which was clicked?
Is it possible to receive in the script a link to the component "BoxCollider" of the object on which they clicked and to delete it ? .... and that way to make it inactive but to stay in the scene...
Answer by Dragate · Nov 10, 2017 at 12:06 PM
On click, you raycast and destroy the BoxCollider component of the first gameobject it hits.
void Update(){
if (Input.GetMouseButtonDown(0)){
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)){
if (hit.collider.GetComponent<BoxCollider>() != null){
Destroy(hit.collider.GetComponent<BoxCollider>());
}
}
}
oh thanks!!!! I have copy paste that in wrong script... now it works perfect. ... hope to be useful to you !!!!! :)
Answer by lernoh · Nov 10, 2017 at 07:31 PM
Thanks a lot for your answer!!!! I've forgot to say that my game is 2d. Its sea battle. and the objects in the Hierarchy called Cvadrat(clone) are exactly my coordinates and they appear after I've pressed play.
... now I need to prevent opportunity of repitiedly shooting at the same coordinates...
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Using a Single Collider to Detect Collisions with Multiple Colliders 3 Answers
OnTriggerEnter not being called with multiple colliders 1 Answer
Photon - Add force to other player 0 Answers
Attempt counter 2 Answers