Hello,
I’m trying to play an animation back and forth. Let me explain: I have a raycast system that checks to see if the object is over Water (tag), or Other. If the object is over water it needs to play the animation normally, if its over other, then it needs to play the animation in reverse.
The problem is, the animation either doesn’t play at all, or only plays half of it.
Here is my code:
var waterSplash : GameObject;
var waterSplashParticle : ParticleEmitter;
var hydraulics : AudioClip;
private var hit : RaycastHit;
function Awake(){
waterSplashParticle.particleEmitter.emit = false;
CheckRaycast();
}
function LateUpdate () {
if(hit.collider.tag == "Water"){
print("Over Water");
waterSplashParticle.particleEmitter.emit = true;
if(playAnim == false){
FoldInWheels();
playAnim = true;
}
}
else if(hit.collider.tag == "Other"){
print("Over Land");
waterSplashParticle.particleEmitter.emit = false;
if(playAnim){
FoldOutWheels();
playAnim = false;
}
}
print("Current Land: "+hit.collider.name+" | "+hit.collider.tag);
}
private var playAnim : boolean = false;
function FoldOutWheels(){
animation["packUp"].speed = -1.0;
animation["packUp"].time = animation["packUp"].length;
animation.Play("packUp");
audio.clip = hydraulics;
audio.Play();
}
function FoldInWheels(){
animation["packUp"].speed = 1.0;
animation.Play("packUp");
audio.clip = hydraulics;
audio.Play();
}
function CheckRaycast(){
while(true){
var direction = transform.TransformDirection (Vector3.up);
var localOffset = transform.position + transform.up * 2;
Physics.Raycast (transform.position, -Vector3.up, hit, 500);
Debug.DrawLine (localOffset, hit.point, Color.blue);
yield WaitForSeconds(0.2);
}
}
Can someone tell me what I am doing wrong? The FoldOutWheels only plays half of the animation, and the FoldInWheels works fine