Ejemplo n.º 1
0
        private void FixedUpdate()
        {
            Vector2 direction = pMov.GetDirection();

            if (direction != Vector2.zero)
            {
                var        angle = Mathf.Atan2(-direction.x, direction.y) * Mathf.Rad2Deg;
                Quaternion desiredLegsRotation = Quaternion.AngleAxis(angle, Vector3.forward);
                eyes.transform.rotation = Quaternion.Slerp(eyes.transform.rotation, desiredLegsRotation, .25f);


                if (direction.x != 0)
                {
                    if (direction.x >= 0)
                    {
                        playerAnimator.SetFloat("SpeedRight", 1f);
                        playerAnimator.SetFloat("SpeedLeft", 0f);
                    }
                    else
                    {
                        playerAnimator.SetFloat("SpeedRight", 0f);
                        playerAnimator.SetFloat("SpeedLeft", 1f);
                    }
                }
                else
                {
                    if (direction.y >= 0)
                    {
                        playerAnimator.SetFloat("SpeedRight", 1f);
                        playerAnimator.SetFloat("SpeedLeft", 0f);
                    }
                    else
                    {
                        playerAnimator.SetFloat("SpeedRight", 0f);
                        playerAnimator.SetFloat("SpeedLeft", 1f);
                    }
                }
            }
            else
            {
                playerAnimator.SetFloat("SpeedRight", 0f);
                playerAnimator.SetFloat("SpeedLeft", 0f);
            }

            float actTime = Time.time;

            if (actTime - starveTimer > starveTimeDelta)
            {
                food        = food - starvePoints;
                starveTimer = actTime;

                if (food <= 0 && isAlive)
                {
                    die();
                }
            }

            hud.setFood(food);

            if (quitPressed > 0)
            {
                Application.Quit();
            }

            if (restartPressed > 0)
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }