Javascript and Unity 5 : What is the error of the code? (Animations jump and fall)

Asked

Viewed 713 times

1

I am following a tutorial to create an infinite racing game (Temple Run style), the tutorial is old and the classes etc changed in Unity 5, so I could not play the code, it is made to control and execute the animations of the character.. If the Start key has been pressed it starts the animation of walking, but the jumping one is not possible because I would have to use Wrapmode to prioritize it, but this is not working.. So by logic I tried like this (tried in other ways, but the game hangs, as in this way).

           #pragma strict
        var anim : Animator; 
        function Start () {
            anim = GetComponent.<Animator>();

        }

        function Update () {
        /*  if(Controle.Start == false){
                anim.SetBool ("ande", false) ;
            }*/
            if(Controle.Start == true){
                anim.SetBool ("ande", true); // Verifica se deu start e inicia a anim de andar
            }
            /*if(Controle.cair == true){
                anim.SetBool ("morra", true); // essa era a de morrer mas está com o mesmo problema
            }*/
            Teste();
        }
        /* Tentei arrumar criando essa função que enquanto o espaço tiver pressionado ele desativa 
    o start e logo após ele executa a animação de pulo, mas não deu, tentei outros jeitos usando 
while mas sem sucesso */
        function Teste(){
            if(Input.GetKey("space")){
                while(Input.GetKey("space")){
                    Controle.Start = false;
                }
                anim.SetBool ("pule", true);
            }
        }

How do I fix this? I tried everything, Wrapmode would be with Getcomponent, but the animations didn’t work with Animation.

  • Usually you say what the mistake is and we try to help you solve it. rs* But why go all the way around to make a Runner? You only need to capture the pressed key and fire a trigger on the animmature, it takes care of the rest.

1 answer

0


function Update() {

// Verifica se deu start
if (Controle.Start == true) { 

   // Caso sejá apertado a tecla Space executa a ação "Pule"
   if (Input.GetKey("space")) { 
      anim.SetBool("pule", true);
      anim.SetBool("ande", false);
   } else { // Senão executa sempre a ação "Ande"
        anim.SetBool("ande", true);
        anim.SetBool("pule", false);
   }   
 }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.