- Home /
Why does my climb stairs animation not play?
I'm trying to make an animation play, when the player is in a trigger(collider) and presses 'Z'. The ladder-climb animation is on the Player and the following script is on the trigger: If some-one can help me, thanks.
#pragma strict
var Player : GameObject;
var IsInTrigger : boolean = false;
function Start () {
guiText.enabled = false;
Player = GameObject.FindWithTag("Player");
}
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){ // remember to tag the player as "Player"
guiText.enabled = true;
IsInTrigger = true;
}
}
function OnTriggerExit(other: Collider){
if(other.tag == "Player"){
guiText.enabled = false;
IsInTrigger = false;
}
}
if(IsInTrigger == true && Input.GetKeyUp(KeyCode.Z)){
Player.animation.Play("ClimbLadder");
IsInTrigger = false;
guiText.enabled = false;
}
Answer by Wobak · Sep 10, 2013 at 09:54 PM
I think you should put the whole if(IsInTrigger....) statement within the Update function or it won't be checked every frame.
Gets me tons of errors:
#pragma strict
var player : GameObject;
var IsInTrigger : boolean = false;
function Start () {
guiText.enabled = false;
player = GameObject.FindWithTag("Player");
}
function Update () {
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){ // remember to tag the player as "Player"
guiText.enabled = true;
IsInTrigger = true;
}
}
function OnTriggerExit(other: Collider){
if(other.tag == "Player"){
guiText.enabled = false;
IsInTrigger = false;
}
}
if(IsInTrigger == true && Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Z)){
Player.animation.Play("ClimbLadder");
IsInTrigger = false;
guiText.enabled = false;
}
}
Don't nest the OnTrigger functions within Update as well - just put the if(IsInTrigger)... block there.
Heh, because you have put your Trigger enter and exit functions in it as well.
Which is probably the cause in the first part, as you haven't got your if statement in the update.
Take those two out and just leave the if statement in the update method.
I suggest you read Wobak's original answer and do ONLY what he specified in the answer. You've moved too much into the update statement.
Your answer
Follow this Question
Related Questions
Getting My FPS Controller To Play An Animation After A Trigger Event 1 Answer
No errors, yet script doesn't work? 0 Answers
Play parent animation without affecting the child animation 1 Answer
Trigger door animation with external trigger 1 Answer
Can a Trigger be triggered by an animated object (script)? 1 Answer