Parser Error

Hey, i was just trying out unity making a FPS survival type thing, and looked at some stuff and managed to complete the code, but i still have one error.

using UnityEngine; using System.Collections;

var damage : int = 50;
var distance : float;
function Update () {

if (Input.GetButtonDown(“Fire1”)) {

var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.transformDirection(Vector3.forward), hit )) {

    distance = hit.distance;
    hit.transform.SendMessage("Apply Damage", damage, SendMessageOptions.DontRequireReciever);

}

}
}

the error is on the first var statement

var damage : int = 50;

The posted source is a mixture of c#(the using statements) and unityscript/javascript(everything else).

You should also always post the full error, otherwise you’re asking people to guess and thats generally a waste of time for you as the poster.

If this is in a file that ends with .cs you’re going to have a bad time. if the file ends with .js, then replace the ‘using’ reserved word to ‘import’, though with unityscript/javascript these are already imported underneath you.

this code belongs in a .js file:

import UnityEngine; 
import System.Collections;

var damage : int = 50; 
var distance : float; 

function Update () 
{
	if (Input.GetButtonDown("Fire1")) {
		var hit : RaycastHit;
		if (Physics.Raycast (transform.position, transform.transformDirection(Vector3.forward), hit )) {
			distance = hit.distance;
			hit.transform.SendMessage("Apply Damage", damage, SendMessageOptions.DontRequireReciever);
		}
	} 
}

if it was meant to be c#:

using UnityEngine; 
using System.Collections;

public class SomeClassName: MonoBehaviour
{
	int damage = 50; 
	float distance; 

	void Update () 
	{
		if (Input.GetButtonDown("Fire1")) {
			RaycastHit hit;
			if (Physics.Raycast (transform.position, transform.transformDirection(Vector3.forward), out hit )) {
				distance = hit.distance;
				hit.transform.SendMessage("Apply Damage", damage, SendMessageOptions.DontRequireReciever);
			}
		} 
	}
}