Can someone please tell me whats wrong with my code - the error syas it expects to see ')' instead it saw 'hit' (the one after 'out')

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

function update ()
{
	if (input.GetButtonDown("fire1"))
	{
		var hit:RaycastHit;
		if (Physics.Raycast (transfrom.position,Transform.TansformDirection(Vector3.hit),out hit)
		{
			Distance=hit.distance;
				if (Distance < MaxDistance)
		{
			hit.transform.SendMessage("ApplyDamage",TheDamage,SendMessageOptions.DontRequireReceiver);
			}
		}
	}
}
  • You are missing a ‘)’ at the end of line 10

  • ‘transform’ is not ‘transform’ on line 10 (the o and r are reversed)

  • You need lower case ‘transform’ in your ‘transform.TransformDirection()’. Lower case ‘t’ is the transform for there current game object. Upper case ‘Transform’ is the class.

  • In Javascript/Unity script you don’t use ‘out’ (line 10).

  • Input is ‘Input’ with an upper case ‘I’ on line 7

  • There is no such thing as Vector3.hit. I’m not sure what you intended here, but I replace it with Vector3.forward in the code below.

  • ‘update’ should be ‘Update’ (thanks @MrSoad)

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

    function Update ()
    {
    if (Input.GetButtonDown(“fire1”))
    {
    var hit:RaycastHit;
    if (Physics.Raycast (transform.position,transform.TransformDirection(Vector3.forward),hit))
    {
    Distance=hit.distance;
    if (Distance < MaxDistance)
    {
    hit.transform.SendMessage(“ApplyDamage”,TheDamage,SendMessageOptions.DontRequireReceiver);
    }
    }
    }
    }