Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (controller.isGrounded && count.isCountDown)
        {
            GetComponent <Animation>().Play("run");

            if (Input.GetKeyDown("left") || gestureListener.IsFlyLeft())
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, -1);
            }
            else if (Input.GetKeyDown("right") || gestureListener.IsFlyRight())
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, 1);
            }
            else
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, 0);
            }

            //moveDirection = new Vector3(tempVectorValue, 0, 0);
            //moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
            //moveDirection = transform.TransformDirection(moveDirection);
            //moveDirection *= speed;


            if (pause.paused == false && pause.enabled == true)
            {
                gameObject.GetComponent <AudioSource>().enabled = true;
            }
            else if (pause.paused == true || count.isCountDown == false)
            {
                gameObject.GetComponent <AudioSource>().enabled = false;
            }


            if (Input.GetKeyDown("left") || gestureListener.IsSwipeLeft())
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, -1);
            }
            else if (Input.GetKeyDown("right") || gestureListener.IsSwipeRight())
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, 1);
            }
            else
            {
                location = CalculateMotion((int)controller.GetComponent <Transform>().localPosition.x, 0);
            }


            //moveDirection = new Vector3(tempVectorValue, 0, 0);
            //moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
            // moveDirection = transform.TransformDirection(moveDirection);
            // moveDirection *= speed;

            if (Input.GetButton("Jump"))
            {
                GetComponent <Animation>().Stop("run");
                GetComponent <Animation>().Play("jump_pose");
                jumpSound.Play();
                gameObject.GetComponent <AudioSource>().enabled = false;
                moveDirection.y = jumpSpeed;
            }
            else if (gestureListener.IsFlap())
            {
                GetComponent <Animation>().Stop("run");
                GetComponent <Animation>().Play("jump_pose");
                jumpSound.Play();
                gameObject.GetComponent <AudioSource>().enabled = false;
                moveDirection.y = jumpSpeed;
            }



            if (controller.isGrounded)    //recursive, extra one, not nessacary
            {
                isGrounded = true;
            }

            if (control.isGameOver)
            {
                gameObject.GetComponent <AudioSource>().enabled = false;
            }
        }

        if (((gestureListener.IsRaiseLeftHand() || gestureListener.IsRaiseRightHand())) && !count.enabled)
        {
            Debug.Log("CountDownStart" + gestureListener.IsRaiseRightHand());
            StartCountDown();
        }

        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);   //used for jump
        controller.transform.localPosition = new Vector3(location, controller.GetComponent <Transform>().position.y, -7);
    }