AI Programing

I am programing an AI script for a first person shooting game and there is one error that I can’t figure out how to solve(expecting }, found ‘’.) Pleas tell me what I’m doing wrong

var playerDirection : Vector3 = (player.position - character.position);
var hit : RaycastHit;
var distance;
var target : Transform;
public var HitPoint : Script;    
var lookAtDistance = 15.0;
var damping = 6.0;
public var OnSpoted : Script;
public var SoundOnSpoted : AudioClip;
public var OnLost : Script;
public var SoundOnLost : AudioClip;
public var OnHit : Script;
public var SoundOnHit : AudioClip;
public var OnFriendlyHit : Script;
public var SoundOnFriendlyHit : AudioClip;
public var OnEnemyHit : Script;
public var SoundOnEnemyHit : AudioClip;
public var OnDie : Script;
public var SoundOnDie : AudioClip;

 
 function Update () 
    {
    distance = Vector3.Distance(target.position, transform.position);

    if(distance < lookAtDistance)
    {

		
function (OnSpoted) {	
 if(distance < lookAtDistance)
   	if (!behaviourOnSpotted.enabled) {
		behaviourOnSpotted.enabled = true;
		behaviourOnLostTrack.enabled = false;
		
		if (audio && soundOnSpotted) {
			audio.clip = soundOnSpotted;
			audio.Play ();
		}
	}

function (OnLost) {
	if (!behaviourOnLost.enabled) {
		behaviourOnLost.enabled = true;
		behaviourOnLost.enabled = false;
	
	if (audio && soundOnLostTrack) {
			audio.clip = soundOnLostTrack;
			audio.Play ();
		}
	}

function (CanSeePlayer) : boolean {
	Physics.Raycast (character.position, playerDirection, hit, playerDirection.magnitude);
	if (hit.collider && hit.collider.transform == player) {
		return true;
	}
	return false;

function (OnHit) {
	if(!behaviorOnHit.enabled) {
		behaviorOnHit.enabled = true;
		behaviorOnHit.enabled = false;

if (audio && soundOnHit) {
			audio.clip = soundOnHit;
			audio.Play ();
		}
	}

function (OnFriendlyHit) {
	if(!behaviorOnFriendlyHit.enabled) {
		behaviorOnFriendlyHit.enabled = true;
		behaviorOnFriendlyHit.enabled = false;

if (audio && soundOnFriendlyHit) {
			audio.clip = soundOnFriendlyHit;
			audio.Play ();
		}
	}

function (OnEnemyHit) {
	if(!behaviorOnEnemyHit.enabled) {
		behaviorOnEnemyHit.enabled = true;
		behaviorOnEnemyHit.enabled = false;

if (audio && soundOnEnemyHit) {
			audio.clip = soundOnEnemyHit;
			audio.Play ();
		}
	}

function (OnDie) {
	if(!behaviorOnDie.enabled) {
		behaviorOnDie.enabled = true;
		behaviorOnDie.enabled = false;

if (audio && soundOnDie) {
			audio.clip = soundOnDie;
			audio.Play (); 
		}
	}

Man, unless you know lots of things about Unityscript that I ignore, your script seems totally wrong - the surprise is to have only one error flagged by the compiler (it became as confused as I, and just pointed a single error). There are some evident errors to fix in your script:

1- Curly braces must always match, and there are lots of open braces without their closing partners.

2- You must declare functions this way:

function CanSeePlayer() : boolean {
    Physics.Raycast (character.position, playerDirection, hit, playerDirection.magnitude);
    if (hit.collider && hit.collider.transform == player) {
        return true;
    }
    return false;
}

Notice that the braces are matched!

3- It seems you’re defining the type of your functions as Script. As far as I know, this type doesn’t even exist. You must declare functions as above - there’s no need to declare them at the top like you did.

4- You must define the variables player and character - they are not defined anywhere in this script.

These are only basic problems. You must match the curly braces, define your functions in the correct way and try again - probably a lot of new errors will appear.