- Home /
Strange issue changing the animation state
The issue is about changing the animation state. Sometimes, as you can watch in the video beneath that, the shots don't work properly. The strangest thing is that it occurs few times and (aparently) radomly.
Note the seconds 0:15, 0:36, 0:41 and 1:06. http://www.youtube.com/watch?v=LGZ30x-DBRA
If there are any sintax error is due to I translated the main code to make it easier to read. The comments or variables in spanish are not related whith the animation. I am asking for help cause I have no idea what kind of pattern follows this issue, so I can't fix it.
Sorry, I know it's a lot of code.
Thanks.
Magnum.cs
void Update () {
// COLLISION AND SHOTS
RaycastHit hit;
//If collision exists
if(Physics.Raycast (transform.position, transform.forward, out hit, 50)){
if (hit.collider.gameObject.tag == "enemy"){
texturaPuntero.color = Color.red;
} else {
texturaPuntero.color = new Color(0.5f,0.5f,0.5f,1f);
}
}
if (Input.GetButtonDown("Reload") && (!LogicaAnimaciones.boolNowShooting || !LogicaAnimaciones.boolNowShooting)){
if ((InformacionArmas.magnumBalasFueraCargador > 0) && (InformacionArmas.magnumBalasCargador < capacidadCargadorMaxima)){
Reload();
LogicaAnimaciones.boolReload = true;
} else {
audio.PlayOneShot(magnumWhithoutAMMO);
}
} else {
LogicaAnimaciones.boolReload = false;
}
//Shooting
if(Input.GetButtonDown("Fire1") && (!LogicaAnimaciones.boolNowShooting || !LogicaAnimaciones.boolNowReload)){
LogicaAnimaciones.boolShot = true;
RaycastHit hitMagnum;
if(Physics.Raycast (transform.position, transform.forward, out hitMagnum, 50)){
tagColision = hitMagnum.collider.gameObject.tag;
//Si hay colisión y SÍ ES UN ENEMIGO
if (tagColision == "enemy"){
if (InformacionArmas.magnumBalasCargador > 0){
Disparar();
//Distingue si le damos en la cabeza o en el cuerpo
if (enemigo.name.Equals("head")){
enemy.transform.parent.SendMessage("UpdateVida", headDamage);
} else {
enemy.transform.parent.SendMessage("UpdateVida", bodyDamage);
}
} else {
audio.PlayOneShot(magnumWhithoutAMMO);
LogicaAnimaciones.boolShot = false;
}
//IT'S NOT AN ENEMY
} else {
if (InformacionArmas.magnumBalasCargador > 0){
Disparar();
LogicaAnimaciones.boolShot = true;
//MINOR CODE
} else {
audio.PlayOneShot(magnumWhithoutAMMO);
//No dejamos que se reproduzca la animación
LogicaAnimaciones.boolShot = false;
}
}
//IF THERE IS NO COLLISION
} else {
if (InformacionArmas.magnumBalasCargador > 0){
Disparar();
} else {
//... Reproducimos el audio
audio.PlayOneShot(magnumWhithoutAMMO);
//No dejamos que se reproduzca la animación
LogicaAnimaciones.boolShot = false;
}
}
} else {
LogicaAnimaciones.boolShot = false;
}
}
void Disparar (){
//MINOR CODE
}
void Reload (){
//MINOR CODE
}
Animation.cs
void FixedUpdate () {
MagnumAnimaciones();
}
//MAGNUM -> Animaciones
void MagnumAnimaciones(){
//DISPARAR O CARGAR. Los bool le llegan de MagnumComportamiento
animacionMagnum.SetBool("Disparar", boolShot);
animacionMagnum.SetBool("Recargar", boolReload);
boolNowShooting = animacionMagnum.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Disparo");
boolNowReload = animacionMagnum.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Recargar");
//LÓGICA PARA ANDAR:
//Si se mueve...
if (!boolNowShooting || !boolNowReload){
if (Input.GetButton("Horizontal") || Input.GetButton("Vertical")){
//... hace que ande
animacionMagnum.SetBool("Andando", true);
//Si no se mueve...
} else {
animacionMagnum.SetBool("Andando", false);
}
}
}
Comment