- Home /
Basic on collision play animation code not working
I am trying to play animation on collision, my script should be almost identical to that of will goldstones - the sounds and the door closing yet, i continue to get errors about = ; : when i replace with those it still says expecting.
var doorOpened : boolean = false;
function OnControllerColliderHit(hit:ControllerColliderHit){ if((hit.gameObject.tag == "drilldooropen") && (doorOpened == false)){ openDoor(); } }
function update () function openDoor(); { doorOpened = true;
var drill = gameObject.FindWithTag("drilldooropen"); drill.animation.Play("Take 001"); }
very new to unity but exp with 3ds animations the animations are fine.
Assets/Standard Assets/Camera Scripts/Opendoor.js(15,2): BCE0043: Unexpected token: function. Assets/Standard Assets/Camera Scripts/Opendoor.js(17,30): BCE0044: expecting :, found '='.}}
sorry, there we are late night really tired maybe thats part of the problem
Answer by skovacs1 · Nov 08, 2010 at 03:20 PM
There are two main problems with your script:
- You declare a function update with nothing after it, no implementation, no semi-colon, nothing.
- You declare a function openDoor, followed by a semi-colon. Then you open a block with a brace. If you were trying to implement the function you just declared, you should not have ended the declaration with that semi-colon.
Here's probably what you wanted:
var doorOpened : boolean = false;
function OnControllerColliderHit(hit:ControllerColliderHit) { if((hit.gameObject.tag == "drilldooropen") && !doorOpened) openDoor(); }
function openDoor() { doorOpened = true;
var drill : GameObject = gameObject.FindWithTag("drilldooropen"); drill.animation.Play("Take 001"); }
Also, a small improvement, rather than having to find the GameObject every time, you could just pass it in:
var doorOpened : boolean = false;
function OnControllerColliderHit(hit:ControllerColliderHit) { if((hit.gameObject.tag == "drilldooropen") && !doorOpened) openDoor(hit.gameObject); }
function openDoor(drill : GameObject) { doorOpened = true;
drill.animation.Play("Take 001"); }
If you're going to have more than one door, your mechanism doesn't seem very scalable. Perhaps you should consider storing whether the door is open on the door rather than the door opener.
thank you for the time you took to look at my mistakes i see where i went wrong and it works perfectly now i have changed it as you said to the door and it works :) thanks
Your answer
Follow this Question
Related Questions
I need help with an error 1 Answer
error help 2 Answers
script not working 2 Answers
Script error. Please Help! 4 Answers
BCE0044: expecting ':' found ';' 1 Answer