Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NachoDA · Apr 04, 2013 at 03:01 AM · animationstate

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Determine in which frame is an Animation currently 2 Answers

UCE0001: ';' expected. Insert a semicolon at the end 1 Answer

Mecanim - changing animation clip speed, through script? 4 Answers

how do u add sound clips to an animation using animation events? 1 Answer

find animation ? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges