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