BCE0044 error: OnControllerColliderHit

I have compare my "OnControllerColliderHit" with the one from ch. 5 and it is identical

But neverless I getthis compile error: BCE0044: expecting (, found 'OnControllerColliderHit'.

private var doorIsopen : boolean = false;
private var doorTimer : float = 0.0;
private var currentDoor : GameObject;

var doorOpenTime : float = 3.0;
var doorOpenSound : AudioClip;
var doorShutSound : AudioClip;

function Update (){

if(doorIsOpen){
        doorTimer += Time.deltaTime;

    }

        if(doorIsOpen){ doorTimer += Time.deltaTime; }
if(doorTimer > 3){
   Door (doorShutSound, false, "doorshut", currentDoor);
   doorTimer = 0.0;
}

function OnControllerColliderHit(hit: ControllerColliderHit){
    if(hit.gameObject.tag == "outpostDoor" && doorIsOpen == false){
        currentDoor = hit.gameObject;
        Door(doorOpenSound, true, "dooropen", currentDoor);
    }
}

function Door (aClip  :  AudioClip,  openCheck  :  boolean, animName  :  String,  thisDoor  :  GameObject){
    audio. PlayOneShot (aClip);
    doorIsOpen = openCheck;

    thisDoor.transform.parent.animation.Play (animName);
}

@script RequireComponent (AudioSource)

best regards

Sigfus

You're creating OnControllerColliderHit() within Update(). You need to add another curly brace after Update(). This could be where my nascent knowledge of javascript show up though.

Even though this question is old it still remains unanswered. So I thought I would go ahead and answer it.

The problem was that you were declaring a function in another function, which is a no-no┬┤ and one of your variable names were wrong.

    private var doorIsOpen : boolean = false;
    private var doorTimer : float = 0.0;
    private var currentDoor : GameObject;
    
    var doorOpenTime : float = 3.0;
    var doorOpenSound : AudioClip;
    var doorShutSound : AudioClip;
    
    function Update ()
    {
    if(doorIsOpen)
    	{
    	doorTimer += Time.deltaTime;
    	}
    	if(doorIsOpen){ doorTimer += Time.deltaTime; 
    	}
    		if(doorTimer > 3)
    		{
    		Door (doorShutSound, false, "doorshut", currentDoor);
    		doorTimer = 0.0;
    	}
    }
    
    function OnControllerColliderHit(hit: ControllerColliderHit)
    {
        if(hit.gameObject.tag == "outpostDoor" && doorIsOpen == false)
    	{
            currentDoor = hit.gameObject;
            Door(doorOpenSound, true, "dooropen", currentDoor);
        }
    }
    
    
    
    function Door (aClip  :  AudioClip,  openCheck  :  boolean, animName  :  String,  thisDoor  :  GameObject)
{
        audio. PlayOneShot (aClip);
        doorIsOpen = openCheck;
    
        thisDoor.transform.parent.animation.Play (animName);
    }
    
    @script RequireComponent (AudioSource)