Ejemplo n.º 1
0
    /***************************************************************************************
     * disables the rendering of the offset pearl, generates a new pearl, and adds a force to the new pearl,
     * and applies it in the direction specified by angle.
     * ************************************************************************************/
    public void ThrowPearl(float angle, float force)
    {
        //if the beaver is currently holding a pearl
        if (pearlRenderer.enabled)
        {
            soundPlayer.PlayClip(throwSound, 1.0f);
            playerStateScript.SetHasPearl(false);

            //remove it from his grasp visually
            colDetectScript.HidePearl();

            // thrower doesn't interatct with pearl for given time
            beaverSprite.transform.FindChild("beaver_pearl_trigger").gameObject.layer = LayerMask.NameToLayer("Non_Interactable");

            Invoke("MakeInteractable", 0.5f);

            //throw the pearl in the right direction
            GameObject thrownPearl = Instantiate(Resources.Load("Pearl")) as GameObject;

            //remember which beaver threw this pearl
            thrownPearl.GetComponent <pearl_behaviour>().SetBeaver(this.transform.gameObject);

            //the pearl starts on the player
            thrownPearl.transform.position = new Vector2(transform.position.x, transform.position.y);

            //find the angle to throw based on the angle found for the pearl_offest
            //Vector3 dir = Quaternion.AngleAxis(aimingDirScript.GetThrowAngle(), Vector3.forward) * Vector3.up;
            Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.up;

            //apply force to the pearl in that direction
            thrownPearl.GetComponent <Rigidbody2D>().AddForce(dir * force);
        }
    }
Ejemplo n.º 2
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);
            }
        }
    }