Mouse position collider questions?

Hello. If I understand this script correctly, it detects when a ray, originating from the player’s cursor position, comes into contact with a collider. How can I have the script only detect when the ray comes into contact with a collider of an object that has a specific tag? Also, once the ray detects a collider, how can I store that specific object as a variable (so that later I could destroy it, move it, etc)? Thanks

If you take a look at the bottom of Physics.Raycast, you'll see that you can use a RaycastHit variable to automatically store the information about the hit collider.

So if you were to use the example script as a base:

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
   Debug.DrawLine (ray.origin, hit.point);
}

We can check the tag quickly with CompareTag or hit.transform.tag, and even assign the object to a variable by way of hit.transform.gameObject.

var myObject : GameObject;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
  if(hit.transform.tag == "Mytag"){
     myObject = hit.transform.gameObject;
  }
}

The example above uses myObject as a variable local to the function. If you'd like to use it some time later in your script, you should initialize it at the head of your script or somewhere else in greater scope.