Esempio n. 1
0
    public void GameUpdate()
    {
        if (_bplay)
        {
            AmbientBackgroundEffect();

            if (_sphere.transform.position.x < -28.2 || _sphere.transform.position.x > 28.2 || _sphere.transform.position.y < _minHeight - 27)              //_lastCameraPositionY - 20)
            {
                GameStop();
            }

            _height = (int)(_sphere.transform.position.y + 8.2f);
            if (_height > _bestHeight)
            {
                _bestHeight      = _height;
                _scoreTitle.text = _bestHeight.ToString() + "m";
            }


            if (Input.GetMouseButtonDown(0))
            {
                _mouseInPos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _mouseClicked = true;
            }

            if (Input.GetMouseButtonUp(0))
            {
                _mouseOutPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _distanceX   = Vector3.Distance(_mouseOutPos, _mouseInPos);

                _cubes [turn].transform.position   = _sampleCube.transform.position;
                _cubes [turn].transform.localScale = _sampleCube.transform.localScale;
                _cubes [turn].transform.rotation   = _sampleCube.transform.rotation;

                _sampleCube.transform.position = new Vector3(0, 0, -20);
                _mouseClicked = false;
            }

            if (_mouseClicked)
            {
                _mouseOutPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _distanceX   = Vector3.Distance(_mouseOutPos, _mouseInPos) * 2;
                float cubeLengthLimit = 10;
                if (_distanceX < cubeLengthLimit)
                {
                    _sampleCube.transform.position   = new Vector3(_mouseInPos.x, _mouseInPos.y, 0);
                    _sampleCube.transform.localScale = new Vector3(_distanceX, 0.1f, 1.0f);
                }
                else
                {
                    _sampleCube.transform.localScale = new Vector3(cubeLengthLimit, 0.1f, 1.0f);
                }

                var relativePos = _mouseOutPos - _mouseInPos;

                Vector3    vec3AxisX  = new Vector3(1.0f, 0.0f, 0.0f);
                Quaternion quaternion = Quaternion.FromToRotation(vec3AxisX, relativePos);
                _sampleCube.transform.rotation = quaternion;
            }
            else
            {
                //_mouseOutPos.z = -10;
                _lastCameraPositionY = _mouseOutPos.y - 5;
                if (_minHeight < _lastCameraPositionY)
                {
                    _minHeight = _lastCameraPositionY;

                    float cameraX;
                    if (_sphere.transform.position.x > 14f)
                    {
                        cameraX = 14f;
                    }
                    else if (_sphere.transform.position.x < -14f)
                    {
                        cameraX = -14f;
                    }
                    else                    //( _sphere.transform.position.x <= 13.5 && _sphere.transform.position.x >= -13.5)
                    {
                        cameraX = _sphere.transform.position.x;
                    }

                    _camera.transform.localPosition = Vector3.Slerp(_camera.transform.localPosition, new Vector3(cameraX, _lastCameraPositionY + 0, -10), Time.deltaTime * 3);
                }
            }
        }
        else             // when game is stopped
                         //_mouseOutPos.z = -10;
        {
            _lastCameraPositionY = _mouseOutPos.y - 5;
            //_camera.transform.localPosition = Vector3.Slerp (_camera.transform.localPosition, new Vector3 (0, _lastCameraPositionY+5, -10), Time.deltaTime * 3);

            if (Input.GetMouseButtonUp(0) && _replay)
            {
                _scoreTitle.gameObject.SetActive(true);
                _bestScoreTitle.gameObject.SetActive(true);
                _levelTitle.gameObject.SetActive(true);
                int temp = PlayerPrefs.GetInt("_bestScore");
                _bestScoreTitle.text = "Best : " + temp.ToString() + "m";

                if (_playCount >= 12)
                {
                    _unityAdsHelper.ShowAds();
                    _playCount = 0;
                }
                _panel.gameObject.SetActive(true);
                _title.gameObject.SetActive(false);
                StartCoroutine("PanelFadeIn", false);

                GameInit();
                _bplay = true;
                StartCoroutine("ClimbUpCAM");
                StartCoroutine("BlockGenerator");
                StartCoroutine("LevelUp");
                _sphere.SphereResume();
                _replay = false;
            }
        }
    }