Esempio n. 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);
            }
        }
    }
Esempio n. 2
0
    void Start()       //初始化时生成方块并调用其GenerateCube函数
    {
        Score.fontSize = 30;

        PreNodes = new List <Vector2> ();

        cubeCount  = new int[2];
        comboCount = new int[1];

        directionIndex = 1;

        camera        = maincamera.GetComponentInChildren <Camera> ();
        cameraControl = maincamera.GetComponent <CameraControl> ();

        offset += xoffset;

        cube      = Instantiate(cubeGenerator, offset, Quaternion.identity) as GameObject;
        generator = cube.GetComponent <cubemeshGenerator> ();
        Renderer renderer = cube.GetComponent <Renderer> ();

        originalColor           = Random.ColorHSV(0f, 0.9f, 0.2f, 0.7f, 0.6f, 0.9f);//初始的随机颜色,v的值不能过小否则会太暗
        renderer.material.color = originalColor;

        float H, S, V;

        Color.RGBToHSV(originalColor, out H, out S, out V);

        Renderer originalRenderer = originalCube.GetComponent <Renderer> ();

        originalRenderer.material.color = Color.HSVToRGB(H - 0.03f, S, V);

        generator.GenerateCube(length, width);
        generator.caculateMoveDir(directionIndex, true);

        PreNodeGenerate(new Vector3(0, 0, 0), length, width);

        cubeCount[1]++;
    }