//private void FixedUpdate()
    //{
    //    _characterController.SimpleMove(Vector3.forward * 0);
    //    playerGrounded = _characterController.isGrounded;
    //}
    // Update is called once per frame
    void Update()
    {
        if (playerVida.GetVida() <= 0)
        {
            return;
        }
        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            if (isJumping == false)
            {
                isJumping = true;
                if (_animator != null)
                {
                    _animator.SetTrigger("jump");
                }
                StartCoroutine(JumpEvent());
            }
            else
            {
                //double jump
                if (canDoubleJump == false || isDoubleJumping)
                {
                    return;
                }
                isDoubleJumping = true;
                StopAllCoroutines();
                StartCoroutine(JumpEvent());
            }
        }
//        playerGrounded = _characterController.isGrounded;
    }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Enemigo")
     {
         vidas--;
         if (vidas == 0)
         {
             muerte = true;
         }
         if (vidas >= 0)
         {
             vida.QuitarVida(1);
             Debug.Log(vida.GetVida());
         }
     }
     if (collision.gameObject.layer == 7)
     {
         numSalto = 0;
     }
 }
Beispiel #3
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.layer == 3)
     {
         vidas--;
         if (vidas == 0)
         {
             muerte = true;
         }
         else
         {
             Vida.QuitarVida(1);
             Debug.Log(Vida.GetVida());
         }
     }
     if (collision.gameObject.layer == 8)
     {
         vuela = false;
     }
     else
     {
         vuela = true;
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (playerVida != null && playerVida.GetVida() <= 0)
        {
            _animator.SetBool("dead", true);
            return;
        }
        inputAndar  = CrossPlatformInputManager.GetAxis("Vertical");
        inputRodar  = CrossPlatformInputManager.GetAxis("Horizontal");
        inputSprint = CrossPlatformInputManager.GetAxis("Fire3");

        if (inputAndar <= 0)
        {
            Andar = velocidadeAndarTras * inputAndar;
        }
        else
        {
            Andar = velocidadeAndar * inputAndar + (velocidadeAndar * inputSprint);
        }

        Vector3 novaPosicao = transform.forward * Andar;

        //deslizar
        if (playerJump.playerGrounded)
        {
            float angulo = Vector3.Angle(Vector3.up, hitNormal);
            // Debug.Log(angulo);
            if (angulo > _characterController.slopeLimit && angulo < 90 && hitHeight < 0.15 && hitHeight > 0)
            {
                novaPosicao    = transform.forward;
                novaPosicao.x += (1f - hitNormal.y) * hitNormal.x * (velocidadeAndar * 2 - slideFriction);
                novaPosicao.z += (1f - hitNormal.y) * hitNormal.z * (velocidadeAndar * 2 - slideFriction);
                novaPosicao.y += Physics.gravity.y * 2;
            }
        }
        else
        {
            novaPosicao.y += Physics.gravity.y;
        }
        _characterController.Move(novaPosicao * Time.deltaTime);
        playerJump.playerGrounded = _characterController.isGrounded;

        if (RodarComTeclado == false)
        {
            if (inputRodar != 0 && inputAndar == 0)
            {
                novaPosicao = transform.right * velocidadeAndar * inputRodar;
                _characterController.Move(novaPosicao * Time.deltaTime);
                if (inputRodar > 0)
                {
                    _animator.SetBool("rightwalk", true);
                }
                if (inputRodar < 0)
                {
                    _animator.SetBool("leftwalk", true);
                }
                //_animator.SetFloat("velocidadelateral", inputRodar);
            }
        }
        else
        {
            _characterController.transform.Rotate(_characterController.transform.up * velocidadeRodar * inputRodar);
        }
        if (inputRodar == 0 || inputAndar != 0)
        {
            _animator.SetBool("rightwalk", false);
            _animator.SetBool("leftwalk", false);
        }
        if (_animator != null)
        {
            _animator.SetFloat("velocidade", inputAndar + (inputAndar * inputSprint));
        }
    }