Esempio n. 1
0
    //This function is called when a rigid body enters the trigger
    void OnTriggerEnter(Collider other)
    {
        //We are checking if the entering object has the Player tag (to make sure it is our character)
        if (other.gameObject.CompareTag("Player"))
        {
            //We store the playerTransform to use it later for checking the distance
            playerTransform = other.gameObject.transform;

            //We get Animator and EdgeGrab components. EdgeGrab is the script that
            //handles grabbing the edge on our character's side.
            Animator anim = other.gameObject.GetComponent <Animator>();
            EdgeGrab grab = other.gameObject.GetComponent <EdgeGrab>();

            if (grab != null)
            {
                //We check if our character is plaing the InAir or Jump animations.
                //Only then we want to trigger the Grab function.
                if (anim.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.InAir") ||
                    anim.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Jump"))
                {
                    //We trigger the Grab() function in the EdgeGrab script attached to the player
                    //It handles the grab on the character's side.
                    grab.Grab(rootTarget);

                    //We disable the trigger's collider to prevent the character from grabbing the edge
                    //again, after it climbs it. We also set the checkToEnable flag to start checking when
                    //we can re-enable the trigger.
                    gameObject.GetComponent <Collider>().enabled = false;
                    checkToEnable = true;
                }
            }
        }
    }
	public static void EndEdge(PlayerControls playa , EdgeGrab edge){
		playa.attachedEdge.GetComponent<EdgeGrab> ().occupied = false;
		playa.edgeGrabbing = false;
		edge.occupant = null;
		playa.PlayerControl = true;
		playa.isGrounded = false;
		playa.anim.SetBool ("edgeGrabbing", false);
		playa.GetComponent<BoxCollider2D> ().enabled = true;
		playa.transform.SetParent (null);
		playa.canBeHit = true;
	}