Пример #1
0
    private void GameLogic()
    {
        boxController.StopAndFall();
        GameObject newBox = GameObject.Find("Box" + (Box.index - 1)) as GameObject;
        GameObject oldBox = GameObject.Find("Box" + (Box.index - 2)) as GameObject;

        print(oldBox);
        print(newBox);
        if (direction)
        {
            if (Mathf.Abs(newBox.transform.position.x - oldBox.transform.position.x) < (newBox.transform.localScale.x + oldBox.transform.localScale.x) / 2)
            {
                //完美下落判断,如果用户点击之后生成盒子位置在参考系方向上与旧盒子的位置差值小于旧盒子边长的10%,则判定为完美下落
                if (Mathf.Abs(newBox.transform.position.x - oldBox.transform.position.x) < oldBox.transform.localScale.x * 0.1)
                {
                    Vector3 newScale = boxController.PerfectFall();
                    print(oldBox);
                    print(newBox);
                    boxController.GenerateNewBox(newBox.transform.localScale, this.ZMoveReference);
                    boxController.Freeze();
                }
                else
                {
                    //进行切割操作并且传入下落旋转方向以及力量方向
                    Vector3 newScale = boxController.SplitBox(new Vector3(newBox.transform.position.x - oldBox.transform.position.x, 0, 0));
                    boxController.GenerateNewBox(newScale, this.ZMoveReference);
                    boxController.Freeze();
                    reward = 0;
                }
                boxController.SpeedIncrease();
            }
            else
            {
                print("You die!");
                status = 2;
            }
        }
        else
        {
            if (Mathf.Abs(newBox.transform.position.z - oldBox.transform.position.z) < (newBox.transform.localScale.z + oldBox.transform.localScale.z) / 2)
            {
                //完美下落判断,如果用户点击之后生成盒子位置在参考系方向上与旧盒子的位置差值小于旧盒子边长的10%,则判定为完美下落
                if (Mathf.Abs(newBox.transform.position.z - oldBox.transform.position.z) < oldBox.transform.localScale.z * 0.1)
                {
                    Vector3 newScale = boxController.PerfectFall();
                    print(oldBox);
                    print(newBox);

                    boxController.GenerateNewBox(newBox.transform.localScale, this.XMoveReference);
                    boxController.Freeze();
                }
                else
                {
                    //进行切割操作并且传入下落旋转方向以及力量方向
                    Vector3 newScale = boxController.SplitBox(new Vector3(0, 0, newBox.transform.position.z - oldBox.transform.position.z));
                    boxController.GenerateNewBox(newScale, this.XMoveReference);
                    boxController.Freeze();
                    reward = 0;
                }
                boxController.SpeedIncrease();
            }
            else
            {
                print("You die!");
                status = 2;
            }
        }
        direction = !direction;
        scoreUpdate();
    }