Raycast clicks on screen rather then just on object.

HI gang, this script works almost perfectly except it activates and deactivates wherever I click in the main camera view Insted of only activating when I click on the object with the script attached to it

#pragma strict
    
    public var Select : Moving;
    
    // this script toggels to turn on and of Selct on Click with raycast like a boss.
    
    
    
    function Start () {
    Select = GetComponent("Moving");
    }
    
    
    
    function Update () { if (Input.GetMouseButtonDown(0)){
          var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
          var hit: RaycastHit;
          if (Physics.Raycast(ray, hit)){
    Select.enabled = !Select.enabled;
    
    
    }
    } 
    }

// feel freee to use this script for yourselves XD

You have to retrieve the hit game object from the raycast you used, like this:

if (Physics.Raycast(ray, hit)){
     if(hit.transform.gameObject == gameObject){
         Select.enabled = !Select.enabled;
     }
}

thanks alot it works perfectly now heres the script incase anyone wats to use it
just renaime the move script to your own scripts

#pragma strict

public var Select : Moving;

// this script toggels to turn on and of Selct on Click with raycast like a boss.



function Start () {
Select = GetComponent("Moving");
}



function Update () { if (Input.GetMouseButtonDown(0)){
      var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      var hit: RaycastHit;
      if (Physics.Raycast(ray, hit)){
       if(hit.transform.gameObject == gameObject){
Select.enabled = !Select.enabled;

}
}
}