How to validate which objects must be destroyed when raycasting?

I’m using raycast to destroy a GameObject when the player click the button
However when the raycast hits the terrain it is also destroyed here is my code:



I want the player can destroy objects but the terrain, Any Idea??

You have to add tag on the object you want to destroy (its on the top of the inspector window). Then you do this:

if(hit.tag == "YourTagText") {

It works Thks !!!