- Home /
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
Answer by Mendicant · Feb 13, 2011 at 03:35 PM
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.
now I have 2 set of errors:
function Update (){ }
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); } }
Answer by FLASHDENMARK · May 28, 2011 at 02:10 PM
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)
Your answer
Follow this Question
Related Questions
Script error. Please Help! 4 Answers
BCE0044: expecting ':' found ';' 1 Answer
ShopScript.Js(49,17): BCE0044 expecting :, found GUI. 1 Answer
Unity MoveAround error 1 Answer