// Update is called once per frame
    void Update()
    {
        // Get the rotation for this frame.
        Vector2 rot = new Vector2();

        if (Input.GetKey(KeyCode.UpArrow))
        {
            rot.y += 1.0f;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            rot.y -= 1.0f;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            rot.x -= 1.0f;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            rot.x += 1.0f;
        }
        rot.Normalize();

        // Try and rotate the camera.
        if (!(rot.x == 0 && rot.y == 0))
        {
            TheCamera.DisablePointing();
        }
        TheCamera.transform.Rotate(rot.y, rot.x, 0);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
#if UNITY_UNITY_ANDROID
        Vector2 touchPos = Input.GetTouch(0).position;

        if (_touchArea.Contains(new Vector3(touchPos.x,
                                            touchPos.y,
                                            0)))
        {
            if (!_lastTouch)
            {
                // this is the first touch so save the touch vector
                _firstTouch = touchPos;
                _isTouch    = true;
            }
            else
            {
                // this is not the first touch
                _isTouch = false;
            }

            //calculate the vector between the first touch and where we are now

            Vector2 newTouch = touchPos - _firstTouch;

            _currentTouch = newTouch;
            _currentTouch.Normalize();

            //Camera testing code
            if (!(_currentTouch.x != 0 && _currentTouch.y != 0))
            {
                theCam.DisablePointing();
            }
            theCam.transform.Rotate(_currentTouch.y, -_currentTouch.x, 0);
        }


        foreach (Touch touch in Input.touches)
        {
            if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
            {
                // if there are touches on the screen
                _lastTouch = true;
            }
            else
            {
                //if there are no touches on the screen
                _lastTouch = false;
            }
        }
#endif
    }