예제 #1
0
    private void die()
    {
        animateController.animate("run", false);
        animateController.animate("jump", false);

        animateController.animate("die", true);
    }
예제 #2
0
    private void die()
    {
        animateController.animate("run", false);
        animateController.animate("jump", false);

        rabbitStats.isDead = true;

        animateController.animate("die", true);
        rabbitStats.isDead = true;
    }
예제 #3
0
    void FixedUpdate()
    {
        CameraConfig cameraWhichFollowsUs = LevelController.current.cameraWhichLooksForRabbit;

        if (this.isVulnerable)
        {
            Physics2D.IgnoreLayerCollision(11, 10, false);
        }
        else
        {
            Physics2D.IgnoreLayerCollision(11, 10, true);
        }


        float value = Input.GetAxis("Horizontal");

        if (Mathf.Abs(value) > 0)
        {
            if (isGrounded)
            {
                cameraWhichFollowsUs.playSoundRabbitWalks();
            }
            moveBody(value);
            animateController.animate("run", true);
        }
        else
        {
            cameraWhichFollowsUs.stopSoundRabbitWalks();
            animateController.animate("run", false);
        }

        if (value < 0)
        {
            spriteRenderer.flipX = true;
        }
        else if (value > 0)
        {
            spriteRenderer.flipX = false;
        }

        Vector3 from     = transform.position + Vector3.up * 0.3f;
        Vector3 to       = transform.position + Vector3.down * 0.1f;
        int     layer_id = 1 << LayerMask.NameToLayer("GroundLayer");
        //Перевіряємо чи проходить лінія через Collider з шаром Ground
        RaycastHit2D hit = Physics2D.Linecast(from, to, layer_id);

        if (hit)
        {
            isGrounded = true;

            if (shouldPlayFallSound)
            {
                shouldPlayFallSound = false;
                cameraWhichFollowsUs.playSoundRabbitFalls();
            }

            //Перевіряємо чи ми опинились на платформі
            if (hit.transform != null && hit.transform.GetComponent <MovingPlatform>() != null)
            {
                //Приліпаємо до платформи
                SetNewParent(this.transform, hit.transform);
            }
        }
        else
        {
            isGrounded          = false;
            shouldPlayFallSound = true;
            SetNewParent(this.transform, this.parent);
        }

        //Намалювати лінію (для розробника)
        Debug.DrawLine(from, to, Color.red);

        //HeroRabit::FixedUpdate
        //Якщо кнопка тільки що натислась
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            this.JumpActive = true;
        }
        if (this.JumpActive)
        {
            //Якщо кнопку ще тримають
            if (Input.GetButton("Jump"))
            {
                this.JumpTime += Time.deltaTime;
                if (this.JumpTime < this.MaxJumpTime)
                {
                    Vector2 vel = myBody.velocity;
                    vel.y           = JumpSpeed * (1.0f - JumpTime / MaxJumpTime);
                    myBody.velocity = vel;
                }
            }
            else
            {
                this.JumpActive = false;
                this.JumpTime   = 0;
            }
        }

        if (this.isGrounded)
        {
            animateController.animate("jump", false);
        }
        else
        {
            animateController.animate("jump", true);
        }
    }