Esempio n. 1
0
    public void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            if (sphere.transform.position.y <= maxY - 10)
            {
                //Если шарик упал, то начать уровень заново
                maxY                      = 0;
                moveDirection             = new Vector3(0, 0, 0);
                sphere.transform.position = new Vector3(0, 0.25f, 0);
                CreateLevel();
            }
        }

        //Направление движения
        moveDirection = new Vector3(0, moveDirection.y - 0.2f, 0);
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveDirection += new Vector3(-1, 0, 0) * Speed;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveDirection += new Vector3(1, 0, 0) * Speed;
        }

        //Шарик движется
        sphere.transform.position += moveDirection * Time.deltaTime;

        scoreText.text = "Score: " + level.Score;

        //Проверка, что шарик на дороге
        if (level.CheckGround(sphere.transform.position))
        {
            if (moveDirection.y <= 0)
            {
                sphere.transform.position -= new Vector3(0, moveDirection.y, 0) * Time.deltaTime;
                moveDirection              = new Vector3(0, 7f, 0);
                maxY = sphere.transform.position.y;
            }
            else
            {
                sphere.transform.position -= new Vector3(moveDirection.x, 0, 0) * Time.deltaTime * 2;
                if (level.CheckGround(sphere.transform.position))
                {
                    sphere.transform.position -= new Vector3(0, moveDirection.y, 0) * Time.deltaTime;
                    moveDirection              = new Vector3(0, 0, 0);
                }
            }
        }
        else
        {
            //Шарик упал
            if (sphere.transform.position.y < maxY - 10)
            {
                //Остановка шарика, чтоб не улетел в бесконечность
                moveDirection  = new Vector3(0, 0, 0);
                scoreText.text = "Score: " + level.Score + "\nSpace to continue";
            }
        }
    }
Esempio n. 2
0
    public void Update()
    {
        if (UnityEngine.Input.GetMouseButtonDown(0))
        {
            if (sphere.transform.position.y <= -10)
            {
                //Если упали, то начинаем уровень заново
                moveDirection             = new Vector3(0, 0, 0);
                sphere.transform.position = new Vector3(0, 0.25f, 0);
                CreateLevel();
            }
            else if (moveDirection.y >= 0)
            {
                //Смена направления
                if (moveDirection.x > 0)
                {
                    moveDirection = new Vector3(0, 0, 1f) * Speed;
                }
                else
                {
                    moveDirection = new Vector3(1f, 0, 0) * Speed;
                }
            }
        }

        //Шарик движется
        sphere.transform.position += moveDirection * Time.deltaTime;

        //Проверка, что шарик на дороге
        if (level.CheckGround(sphere.transform.position))
        {
            scoreText.text = "Score: " + level.Score;
        }
        else
        {
            //Шарик упал с дороги
            if (sphere.transform.position.y > -15)
            {
                moveDirection += new Vector3(0, -1f, 0);
            }
            else
            {
                //Остановим шарик, чтоб не улетел в бесконечность
                moveDirection  = new Vector3(0, 0, 0);
                scoreText.text = "Score: " + level.Score + "\nTap to continue";
            }
        }
    }