Objects with shared tags, delete currently selected?

I want to delete the game object I’m looking at, I’ve set it a tag “Paper” but because I have multiple objects with the same tag it seems to delete them in sequence and not the one I’m staring at… How can I fix this?

var PageCount : GUIText;

function Update () {
	
if ( Input.GetMouseButtonDown(0) )
   {
   	var hit : RaycastHit;
   	var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      if (Physics.Raycast (ray, hit, 0.8))
      {
         Destroy(GameObject.FindWithTag("Paper"));
         PageCount.guiText.text = PageCount.guiText.text + "O";
      }
   }
	
}

if (Physics.Raycast (ray, hit, 0.8))
{
if (hit.transform.gameObject.tag == “Paper”)
Destroy(hit.transform.gameObject);

I asked for something similar two days ago, try this:

  function Update(){
  
  var hit : RaycastHit;

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  
    if (Physics.Raycast (ray, hit, 200))
      {
      
         hit.transform.SendMessage("Touched",hit, SendMessageOptions.DontRequireReceiver);
        

 }
 }

With this you don’t require a tag to hit the object, just create a script with the “Touched” function and add it to every object you want to get destroyed, add inside that function whatever you want to happen if the obj is clicked, then add this code to the camera. Hope it helps :slight_smile: