Beispiel #1
0
    // Use this for initialization
    public void moveBox()
    {
        int currentCam = camListen.getCurrentCamera();          //Get the current camera mode (1 = 2D - 2 = 3D - 3 = 3D Kinect)

        //Check that the Fire1 Buton is pressed the current camera is 2D mode and the collider is set to push RIGHT
        if (Input.GetButton("Fire1") && currentCam == 0 && collider == "rightPushCollider")
        {
            charAnimRotation.playingAnim("PushWalk");                           //Play animation
            if (Input.GetAxis("Horizontal") < 0)                                //If controller is pushed LEFT
            //Move this Object X by the Push Speed and the Time.deltaTime (Time in seconds to complete the last frame)
            {
                this.transform.position = new Vector3(this.transform.position.x - (woodBoxPushSpeed * Time.deltaTime / 2), this.transform.position.y, this.transform.position.z);
            }
            if (Input.GetAxis("Horizontal") > 0)                                //If controller is pushed RIGHT
            {
                charAnimRotation.playingAnim("PushWalk");                       //Play animation
                //Move this Object X by the Push Speed and the Time.deltaTime (Time in seconds to complete the last frame)
                this.transform.position = new Vector3(this.transform.position.x + (Input.GetAxis("Horizontal") * Time.deltaTime * woodBoxPullSpeed), this.transform.position.y, this.transform.position.z);
            }
            //Check that the Fire1 Buton is pressed the current camera is 2D mode and the collider is set to push Left
        }
        else if (Input.GetButton("Fire1") && currentCam == 0 && collider == "leftPushCollider")
        {
            if (Input.GetAxis("Horizontal") > 0)                                //If controller is pushed LEFT
            //Move this Object X by the Push Speed and the Time.deltaTime (Time in seconds to complete the last frame)
            {
                this.transform.position = new Vector3(this.transform.position.x + (woodBoxPushSpeed * Time.deltaTime / 2), this.transform.position.y, this.transform.position.z);
            }
            if (Input.GetAxis("Horizontal") < 0)                        //If controller is pushed RIGHT
            //Move this Object X by the Push Speed and the Time.deltaTime (Time in seconds to complete the last frame)
            {
                this.transform.position = new Vector3(this.transform.position.x + (Input.GetAxis("Horizontal") * Time.deltaTime * woodBoxPullSpeed), this.transform.position.y, this.transform.position.z);
            }
        }
    }
    public void movement()
    {
        if (messageMode)        //Stops all character movement input if the player is in messageMode
        {
            moveDirection = new Vector3(0, 0, 0);
        }

        transform.localEulerAngles = new Vector3(0, 0, 0);                     //Set angle to X 0, Y 0, Z 0

        CharacterController controller = GetComponent <CharacterController>(); //Gets reference for CharacterController

        // If character is on the ground and not stopMovement mode and not in Message mode
        if (controller.isGrounded && !stopMovement && !messageMode)
        {
            //Move on the X axis the Horizontal controller input
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
            //Check if player is pushing RIGHT and not pushing an object
            if (Input.GetAxis("Horizontal") > 0 && !pushingObject)
            {
                //play Animation
                charAnimRotation.walk2DR();
                charAnimRotation.playingAnim("Run");
                //Check if player is pushing LEFT and not pushing an object
            }
            else if (Input.GetAxis("Horizontal") < 0 && !pushingObject)
            {
                //play Animation
                charAnimRotation.walk2DL();
                charAnimRotation.playingAnim("Run");
            }
            else
            {
                //No input - play idle Animation
                charAnimRotation.playingAnim("Idle");
            }

            //Store changes to direction/movement
            moveDirection  = transform.TransformDirection(moveDirection);
            moveDirection *= speed;

            //Jump from grounded position
            if (Input.GetButtonDown("Jump"))
            {
                //Move up on the Y axis
                moveDirection.y = jumpSpeed;
            }
        }


        if (!controller.isGrounded && !stopMovement && !messageMode)
        {
            //play animation
            charAnimRotation.playingAnim("Jump");
            moveDirection.x  = Input.GetAxis("Horizontal");             //Move the player horizontal while in the air
            moveDirection.x *= speed;                                   //Adjust speed
        }

        moveDirection.y -= gravity * Time.deltaTime; //applies a pull to the ground

        //apply movement
        controller.Move(moveDirection * Time.deltaTime); //
        transform.position = new Vector3(transform.position.x, transform.position.y, 0);
        //Store yPos for comparison of last yPos
        yPos = transform.position.y;
    }