Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        /*if((speedUpTime + 5) < Time.time)
        {
            playerSpeed += 0.1f;
            speedUp += 0.1f;
            speedUpTime = Time.time;
            playerSpeedEvent(playerSpeed);
        }*/

        if (transform.position.x >= 7000)
        {
            resetEvent(transform.position.x);
            Vector3 pos = transform.position;

            transform.position = new Vector3(0f, pos.y, pos.z);

        }
        this.transform.Translate(playerSpeed, 0f, 0f);
        //print("local " + transform.localPosition);
        //print("global " + transform.position);
        // float dpos = 0.0f;
        if (Input.touchCount > 0)
        {
            Vector2 rightTouch = new Vector2();
            bool rightBool = false;
            Vector2 leftTouch = new Vector2();
            bool leftBool = false;

            foreach (Touch tch in Input.touches)
            {
                //if the touch is on the right side of the screen
                if (tch.position.x > (Screen.width / 2))
                {
                    rightTouch.x = tch.deltaPosition.x;
                    rightTouch.y = tch.deltaPosition.y;
                    rightBool = true;
                    //print("Right touch = " + tch);
                    // print("Right local touch = " + tch);

                }

                if (tch.position.x < (Screen.width / 2))
                {

                    if(tch.deltaPosition.y == 0)
                    {
                        stillCount++;
                    }

                    //print(tch.deltaTime);
                    if (tch.deltaPosition.y > 0.1f)
                    {
                        animator.SetBool("tiltOut", true);
                        animator.SetBool("tiltIn", false);
                        currentZState  = zState.far;
                        //playerStateEvent(currentZState);
                        stillCount = 0;
                    } else if (tch.deltaPosition.y < -0.1f)
                    {
                        animator.SetBool("tiltIn", true);
                        animator.SetBool("tiltOut", false);
                        currentZState = zState.close;
                        //playerStateEvent(currentZState);
                        stillCount =0;
                    }
                    else if(stillCount > 10)
                    {
                        print("sationary touch");
                        animator.SetBool("tiltOut", false);
                        animator.SetBool("tiltIn", false);
                        currentZState = zState.center;
                        //playerStateEvent(currentZState);

                    }

                    leftTouch.x = tch.deltaPosition.x;
                    leftTouch.y = tch.deltaPosition.y;
                    leftBool = true;
                }

            }

            if (rightBool)
            {

                float boostConstant = 1f;
                if(boostActive)
                {
                    boostConstant = boostSpeed/2;
                }

                float newX = rightTouch.x * 0.8f * boostConstant + speedUp;

                if(rightTouch.x < 0)
                    newX = 2 * newX;

                if ((transform.position.x + newX) >= (30 + mCamera.transform.position.x))
                {
                    if(!boostActive)
                    {
                        //ActivateBoost();
                    }
                    else
                    {
                        newX = 0.0f;
                    }
                }
                else if ((transform.position.x + newX) <= -30 + mCamera.transform.position.x)
                {
                    if(!boostActive)
                    {
                        //ActivateBoost();
                    }
                    else
                    {
                        newX = 0.0f;
                    }
                }

                float newY = rightTouch.y * 0.8f * boostConstant + speedUp;

                if ((transform.position.y + newY) >= 20 + mCamera.transform.position.y)
                {
                    if(!boostActive)
                    {
                        //ActivateBoost();
                    }
                    else
                    {
                        newY = 0.0f;
                    }
                } else if ((transform.position.y + newY) <= -20 + mCamera.transform.position.y)
                {
                    if(!boostActive)
                    {
                        //ActivateBoost();
                    }
                    else
                    {
                        newY = 0.0f;
                    }
                }

                this.transform.Translate(newX, newY, 0f);
            }

            if (leftBool)
            {
                float newZscale = leftTouch.y; //* //0.5f;
                float newZPos = leftTouch.y; //* 1.5f;

                //print("NewZ delta = " + newZ);

                ////translate the player position.z by the oppisite of newZ

                if (transform.position.z - newZPos <= -15f)
                {
                    //newZscale = 0f;
                    newZPos = 0f;
                }
                else if (transform.position.z - newZPos >= 60f)
                {
                    //newZscale = 0f;
                    newZPos = 0f;
                }
                transform.Translate(0f, 0f, -newZPos );

                //transform.localScale += new Vector3(newZscale, newZscale, newZPos);
                //print("localscale after = "+ transform.localScale);

                if(leftTouch.y > 0)
                {
                    //currentZState  = zState.far;
                    //playerStateEvent(currentZState);
                }
                if(leftTouch.y < 0)
                {
                    //currentZState = zState.close;
                    //playerStateEvent(currentZState);
                }

            }

        } else
        {
            animator.SetBool("tiltOut", false);
            animator.SetBool("tiltIn", false);
            stillCount = 0;
            //currentZState = zState.center;
            //playerStateEvent(currentZState);
        }
        //get the acceleration difference on z axis
        AccelX = Input.acceleration.x;

        //print("x accel = " + Input.acceleration.x);
        //print("player angle = " + PlayerAngle

        PlayerAngle = 2.0f;
        if (AccelX > 0.3)
        {
            //PlayerAngle += 0.05f;
            this.transform.Rotate(new Vector3(0,0,1) ,PlayerAngle,Space.World);
            //boostActive = true;

        }
        else if (AccelX < -0.3)
        {
            //PlayerAngle -= 0.05f;
            this.transform.Rotate(new Vector3(0,0,1), -1 * PlayerAngle, Space.World);
            //boostActive = true;
        }
        /*if (Input.acceleration.z > 0.6)
        {
            if (zpos != 1)
            {
                transform.Translate(0f, 0f, 5f);
                zpos++;
            }
        } else if (Input.acceleration.z < -0.6)
        {
            if(zpos != -1)
            {
                transform.Translate(0f, 0f, -5f);
                zpos--;
            }
        }*/

           // print("accel z = " + Input.acceleration.z);
    }
Exemplo n.º 2
0
    void Start()
    {
        animator = GetComponent<Animator> ();
        animator.SetBool("tiltOut",false);
        animator.SetBool("tiltIn", false);
        speedUpTime = Time.time;

        currentZState = zState.center;
    }