Esempio n. 1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Pearl")
        {
            Destroy(other.gameObject);


            if (gameObject.tag == "Left_Clam")
            {
                scoreKeeperScript.IncrementLeftScore();

                clamSprite.material.color = leftScoredColor;
            }
            else if (gameObject.tag == "Right_Clam")
            {
                scoreKeeperScript.IncrementRightScore();

                clamSprite.material.color = rightScoredColor;
            }

            animator.SetTrigger("scored");

            //Wait a little bit before spawning a new pearl
            Invoke("CreateNewPearl", 1.5f);
        }
        else if (other.tag == "Player")
        {
            player_state        playerStateScript     = other.gameObject.GetComponentInParent <player_state>();
            collision_detection playerCollisionScript = other.gameObject.GetComponentInParent <collision_detection>();

            if (playerStateScript.GetHasPearl())
            {
                playerCollisionScript.HidePearl();

                playerStateScript.SetHasPearl(false);

                if (gameObject.tag == "Left_Clam")
                {
                    scoreKeeperScript.IncrementLeftScore();

                    clamSprite.material.color = leftScoredColor;
                }
                else if (gameObject.tag == "Right_Clam")
                {
                    scoreKeeperScript.IncrementRightScore();

                    clamSprite.material.color = rightScoredColor;
                }

                animator.SetTrigger("scored");

                //Wait a little bit before spawning a new pearl
                Invoke("CreateNewPearl", 1.5f);
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        switch (dashState)
        {
        case DashState.Dashing:
            //show the player dashing animation
            animator.SetBool("is_dashing", true);


            dashTimer += Time.deltaTime * 5;
            if (dashTimer >= maxDash)
            {
                //stop the player dashing animation
                animator.SetBool("is_dashing", false);
                //changing player state
                playerStateScript.SetIsDashing(false);

                dashTimer = maxDash;
                //r_body.velocity = savedVelocity;
                dashState = DashState.Cooldown;
            }
            break;

        case DashState.Cooldown:

            dashTimer -= Time.deltaTime;
            if (dashTimer <= 0)
            {
                dashTimer = 0;
                dashState = DashState.Ready;
            }
            break;

        case DashState.Ready:
            //if dash button is pressed, set velocity...
            if (dashInputScript.GetDashButton())
            {
                if (!playerStateScript.GetHasPearl() && !playerStateScript.GetIsHit())
                {
                    // savedVelocity = r_body.velocity;


                    //find the angle to dash based on the angle player is facing
                    Vector3 dir;
                    if (movingScript.GetFacingRight())
                    {
                        dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 90f, Vector3.forward) * Vector3.up;
                    }
                    else
                    {
                        dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 270f, Vector3.forward) * Vector3.up;
                    }


                    //apply force to the player in that direction
                    GetComponent <Rigidbody2D>().AddForce(dir * dashVelocity);

                    //adding the dash burst to the player velocity
                    //r_body.AddForce(new Vector2(dashVelocity * 1f, dashVelocity * 1f));
                    //changing player state
                    playerStateScript.SetIsDashing(true);

                    dashState = DashState.Dashing;

                    //splashSound.Play();
                    soundPlayer.PlayClip(dashSound, 1.0f);
                }
            }
            break;
        }
    }