JavaScript and Unity 5: What is the error of the code? (Leap and fall animations)

1

I'm following a tutorial to create an infinite race game (Temple Run style), the tutorial is old and the classes etc changed in Unity 5, so I could not reproduce the code, it's done to control and execute the animations of the character .. If the Start key was pressed it starts the walking animation, but the skip does not give because I would have to use WrapMode to give priority to it, but that is not working .. So by logic I tried like this ( I tried other ways, but the game crashes, like that).

           #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 already tried everything, WrapMode would be with GetComponent., but the animations did not work with Animation.

    
asked by anonymous 03.05.2015 / 07:38

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);
   }   
 }

}

    
29.09.2015 / 16:29