IEnumerator RunScene()
    {
        CharacterController   gagController = GetAwayGuy.GetComponent <CharacterController> ();
        CharacterController   egController  = EatenGuy.GetComponent <CharacterController> ();
        OneWayPlatformTrigger platform1     = FallThroughPlatformTrigger1.GetComponent <OneWayPlatformTrigger>();
        OneWayPlatformTrigger platform2     = FallThroughPlatformTrigger2.GetComponent <OneWayPlatformTrigger>();

        // Steal camera, disable player input
        Cam.GetComponent <CameraController> ().Target          = GetAwayGuy;
        Player.GetComponent <ProtagController> ().inputEnabled = false;

        gagController.Walk("right");
        egController.Walk("right");
        yield return(new WaitForSeconds(5.0f));        // Just walkin' along like nothing's up

        Debug.Log("Have eaten guy be eaten (trigger animations and such) and show '!' over get away guy");
        egController.Idle();
        gagController.Idle();
        yield return(new WaitForSeconds(1.0f));        // freaking out time

        gagController.Run("left");
        platform1.manuallyPassThrough = true;          // simulate the creature "pressing down" to fall through by manually disabling the platform
        yield return(new WaitForSeconds(1.3f));        // running back time

        gagController.Run("right");

        yield return(new WaitForSeconds(2.3f));        // down the first ramp going right

        platform1.manuallyPassThrough = false;         // cleaning up after ourselves

        gagController.Run("left");
        platform2.manuallyPassThrough = true;

        yield return(new WaitForSeconds(1.75f));        // down the second ramp going left

        gagController.Run("right");

        yield return(new WaitForSeconds(4.75f));        // running for the tree

        platform2.manuallyPassThrough = false;

        gagController.Idle();

        yield return(new WaitForSeconds(0.5f));        // catches his breath for a second

        // and, relealizing that the danger is past, he meanders around the tree
        Dictionary <string, object> arguments = new Dictionary <string, object>();

        arguments.Add("period", 2.0f);
        arguments.Add("subject", GetAwayGuy);
        GetAwayGuy.GetComponent <MovementAnimations>().SetAnimation("WalkBackAndForth", arguments);

        yield return(new WaitForSeconds(5.0f));         // show him walking around tree for a couple seconds

        // return control to the player
        Cam.GetComponent <CameraController> ().Target          = Player;
        Player.GetComponent <ProtagController> ().inputEnabled = true;
    }
Пример #2
0
    // Use FixedUpdate() for Physics stuff
    void FixedUpdate()
    {
        //Check if grounded, and grab ground data
        grounded = GroundedCheck();
        //grounded = Physics2D.OverlapArea (groundCheckTopLeft.position, groundCheckBottomRight.position,  whatIsGround);

        //Jump Input
        almostGrounded = Physics2D.OverlapCircle(almostGroundedCheck.position, almostGroundedRadius, whatIsGround);

        //Horizontal Input
        float move;

        if (inputEnabled)
        {
            move = Input.GetAxis("Horizontal");
        }
        else
        {
            move = 0.0f;
        }

        //Set Velocity based on Inputs
        targetVelocity   = rigidbody2D.velocity;
        targetVelocity.x = move * maxSpeed;

        if (grounded)
        {
            if (Input.GetButtonDown("Jump") && inputEnabled)    //I like "GetButtonDown over GetAxis because holding the button doesn't yield repeaded jumping - as you should =-)
            {
                targetVelocity.y     = jumpVelocity;            //Use velocity for jumps instead of force - yields more consistent jump heights
                grounded             = false;
                rigidbody2D.velocity = targetVelocity;
            }
            else
            {
                if (targetVelocity.y < 0.0f)
                {
                    targetVelocity.y = 0;
                    targetVelocity  -= groundCastHit[0].normal;
                }
                GameObject groundObject = groundCastHit[0].collider.gameObject;

                if (Input.GetButtonDown("Crouch") && inputEnabled)
                {
                    OneWayPlatformTrigger owpt = groundObject.GetComponentInChildren <OneWayPlatformTrigger>();
                    if (owpt)
                    {
                        owpt.manuallyPassThrough = true;
                    }
                }

                rigidbody2D.MovePosition(rigidbody2D.position + targetVelocity * Time.fixedDeltaTime);
            }
        }

        rigidbody2D.velocity = targetVelocity;

        //Set Animation Variables
        anim.SetBool("Grounded", grounded);
        anim.SetBool("AlmostGrounded", almostGrounded);
        anim.SetFloat("Speed", Mathf.Abs(move));
        //anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);//Commented out because it doesn't exist in the animation controller and was throwing warnings

        //Set Facing Direction
        if ((move > 0 && direction == -1) || (move < 0 && direction == 1))
        {
            Flip();
        }
    }