Exemple #1
0
    void Update()       //每次触发时,生成新的方块,调用PerStepAddColor来获取新方块的颜色
    {
        if (length >= 0.02f && width >= 0.02f)
        {
            if (Input.GetMouseButtonDown(0))
            {
                generator.stopMove();

                caculateBreakPos();

                offset = CaculateOffset();

                cube = Instantiate(cubeGenerator, offset, Quaternion.identity) as GameObject;

                generator = cube.GetComponent <cubemeshGenerator> ();
                Renderer renderer = cube.GetComponent <Renderer> ();    //获取组件
                originalColor           = PerStepAddcubeColor(originalColor);
                renderer.material.color = originalColor;                //计算每个新的方块的颜色
                generator.GenerateCube(length, width);
                generator.caculateMoveDir(directionIndex, true);

                cameraMove += new Vector3(0, squaresize / 4f, 0);
                cameraControl.SetMovement(cameraMove);

                cubeCount [1]++;
                cubeCount [0]++;

                if (cubeCount [1] >= 15)
                {
                    cameraControl.ChangeCameraBColor();

                    cubeCount [1] = 0;
                }
            }
            Score.text = cubeCount [0].ToString();
        }
        else
        {
            Destroy(cube);
            Score.text     = "Last Score is " + cubeCount[0].ToString() + "! Press R to restart.";
            Score.fontSize = 15;
            if (Input.GetKeyDown(KeyCode.R))
            {
                SceneManager.LoadScene("main", LoadSceneMode.Single);
            }
        }
    }