- Home /
No errors, yet script doesn't work?
I'm just trying to emulate simple boat physics by animations by attaching the animation component to a rigidbody, but the children of the rigidbody are the ones that are animated. For the animations to play at certain times I have this script:
var Normal : AnimationClip;
var Land : AnimationClip;
var Air : AnimationClip;
var Crash : AnimationClip;
var Idle : AnimationClip;
function Awake(){
Normal.animation.Stop();
Land.animation.Stop();
Crash.animation.Stop();
Air.animation.Stop();
Idle.animation.Play();
}
function Update(){
if(Input.GetKey("up") != null){
Idle.animation.Stop();
}
else{
Idle.animation.Crossfade();
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Water"){
Crash.animation.Stop();
Air.animation.Stop();
Land.animation.Play();
yield WaitForSeconds (1.450);
Normal.animation.wrapMode = WrapMode.Loop;
}
if(other.tag == "Wall"){
Normal.animation.Stop();
Land.animation.Stop();
Air.animation.Stop();
Crash.animation.Play();
yield WaitForSeconds (1.967);
Normal.animation.wrapMode = WrapMode.Loop;
}
if(other.tag == "Jump"){
Normal.animation.Stop();
Land.animation.Stop();
Crash.animation.Stop();
Air.animation.Stop();
}
}
function OnTriggerExit(other : Collider){
if(other.tag == "Water"){
Normal.animation.Stop();
Land.animation.Stop();
Crash.animation.Stop();
Air.animation.Stop();
}
if(other.tag == "Jump"){
Normal.animation.Stop();
Land.animation.Stop();
Crash.animation.Stop();
Air.animation.Play();
}
}
The rigidbody has the trigger and script on it and I have the animations linked to it in the inspector. No errors happen, but the script is ignored and I've no idea why. Any answers/ideas would be greatly appreciated.
For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Fixed Script format. I clicked the 10101 button, then pasted the script.
Try inserting these lines:
//just after line 24
Debug.Log("OnTriggerEnter: + other.Tag);
//just under line 50
Debug.Log("OnTriggerExit: + other.Tag);
They should help confirm in the collisions are detected, tags match, correct order etc.
Those lines actually made it responsive thanks ever so much, but I also found out that I had to change the Normal.animation.Stop() for example, to animation.Stop("Normal") and change the animation names. But thanks anyway that did help.