예제 #1
0
    //кнопка старта
    void OnGUI()
    {
        int posX = Screen.height / 2;
        int posY = Screen.width / 2;

        switch (GameMode)
        {
        case 0:
            if (GUI.Button(new Rect(new Vector2(posX, posY - 100), new Vector2(200, 30)), "Start"))
            {
                CreateSnake();
            }
            if (GUI.Button(new Rect(new Vector2(posX, posY - 40), new Vector2(200, 30)), "Quit"))
            {
                Application.Quit();
            }
            break;

        case 1:
            SnakeLive S = SnakeObj.GetComponent <SnakeLive>();

            int Score = 0;

            if (S != null)
            {
                Score = S.ScoreSnake;
            }
            GUI.Label(new Rect(new Vector2(posX + 100, 0), new Vector2(200, 30)), "Score:" + Score);

            break;
        }
    }
예제 #2
0
    void OnCollisionEnter(Collision collision)
    {
        SnakeLive S = collision.gameObject.GetComponent <SnakeLive>();

        if (S != null)
        {
            S.SnakeDestroy(); //исчезновение змеи при ударе со стеной
        }
    }
예제 #3
0
    //логика яблока, срабаывает при столкновении объектов
    void OnCollisionEnter(Collision collision)
    {
        SnakeLive S = collision.gameObject.GetComponent <SnakeLive>();

        if (S != null)
        {
            S.AddChank();                   //увеличили хвост
            S.ScoreSnake++;                 //увеличили кол-во очков

            DestroyObject(this.gameObject); //удаление яблока
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (SnakeObj != null)
        {
            XX = 0;
            YY = 0;
            if (Input.GetAxis("Horizontal") > 0)
            {
                XX = 1;
            }
            if (Input.GetAxis("Horizontal") < 0)
            {
                XX = -1;
            }
            if (Input.GetAxis("Vertical") > 0)
            {
                YY = 1;
            }
            if (Input.GetAxis("Vertical") < 0)
            {
                YY = -1;
            }

            if ((XX != 0) || (YY != 0))
            {
                SnakeLive S = SnakeObj.GetComponent <SnakeLive>();

                if (XX != 0)
                {
                    S.DirectionHod = new Vector2(XX, 0);
                }
                if (YY != 0)
                {
                    S.DirectionHod = new Vector2(0, YY);
                }
            }
        }
        else
        {
            GameMode = 0;
        }

        if (GameMode > 0)
        {
            Buff++;
            if (Buff > TimeSpeed)
            {
                AddEat();
                Buff = 0;
            }
        }
    }