Beispiel #1
0
 protected void Awake()
 {
     if (m_instance == null)
     {
         m_instance = this;
     }
     else if (m_instance != this)
     {
         Debug.LogWarning("GyroscopeManager.Awake() - instance already exists!");
         Destroy(gameObject);
     }
 }
Beispiel #2
0
    private void FixedUpdate()
    {
#if UNITY_ANDROID
        if (Settings.IsPlayWithMotion())
        {
            _tiltValue = GyroscopeManager.GetXFlatTilt();
            if (_tiltValue < 0)
            {
                if (_tiltValue >= -11)
                {
                    // move left slowly
                    //transform.Translate(Vector2.left * Time.fixedDeltaTime * -_tiltValue * speedRange / 11);
                    // 5.6 for speed range of 6    4.6 for speed range of 5
                    transform.Translate(Vector2.left * Time.fixedDeltaTime * (Mathf.Log10(-_tiltValue + 1) * 5f));  // if you change speedrange you should change 4.6
                }
                else if (_tiltValue < 11)
                {
                    // move left at max speed allowed
                    transform.Translate(Vector2.left * Time.fixedDeltaTime * 5.207f);    //log(11) * 4.6 = 4.79
                }
                else
                {
                    // don't move
                }
            }
            if (_tiltValue > 0)
            {
                //transform.Rotate(Vector3.up, Time.fixedDeltaTime * angularSpeed * tiltValue);
                if (_tiltValue <= 11)
                {
                    // move right slowly
                    // transform.Translate(Vector2.right * Time.fixedDeltaTime * _tiltValue * speedRange / 11);
                    transform.Translate(Vector2.left * Time.fixedDeltaTime * -(Mathf.Log10(_tiltValue + 1) * 4.6f));  // if you change speedrange you should change 4.6
                }
                else if (_tiltValue > 11)
                {
                    // move right at max speed allowed
                    transform.Translate(Vector2.right * Time.fixedDeltaTime * 4.79f);
                }
                else
                {
                    // don't move
                }
            }
        }
        else // no motion
        {
            if (Input.touchCount > 0)
            {
                Touch touch = Input.GetTouch(0);
                if (touch.position.x < Screen.width / 2)
                {
                    transform.Translate(Vector2.left * Time.fixedDeltaTime * speedRange * .68f);
                }
                else
                {
                    transform.Translate(Vector2.right * Time.fixedDeltaTime * speedRange * .68f);
                }
            }
        }
#endif
    }
Beispiel #3
0
 private void OnDestroy()
 {
     m_instance = null;
 }