Could someone explain to me the code in the last two line? I’m a bit confused by it. Also is hit a gameobject because it was referenced as a variable. That is why its able to access transform?

var TheDamage : int = 50;
var Distance : float;

    function Update ()
    		var hit : RaycastHit; 
    		if(Physics.Raycast (Transform.position, transform.TransformDirection(Vector3.foward),hit))
    		Distance = hit.distance; 
    		hit.transform.SendMessage("ApplyDamage"), The Damage, SendMessageOptions.DontRequireReceiver;

In you case

  1. when you click, a ray is send from position “Transform.position” in forward direction.
  2. RaycastHit “hit” returns you all the details about the object your ray hit.
  3. " hit.distance " returns distance from the ray’s origin to the impact point i.e enemy in ur case or in other words “how far the gameobject/enemy is far from ray’s origin( your gun aim)”
  4. hit.transform.SendMessage("ApplyDamage", The Damage, SendMessageOptions.DontRequireReceiver) this will call the method ApplyDamage(float damage_amount) which in some other script

I have assumed that ApplyDamage() has a float type argument