Ejemplo n.º 1
0
    private void Update()
    {
        if (previewCube != null && Camera.main != null)
        {
            if (GridController.IsGridEnabled())                                                                                                                                                                       // Position cube in front of the controller in invisible grid by rounding the x,y,z position
            {
                previewCube.transform.position = new Vector3(Mathf.RoundToInt((transform.position.x + transform.forward.x * 2) / GridController.GridSize) * GridController.GridSize + (GridController.GridSize / 2),  //* previewCube.transform.localScale.x,
                                                             Mathf.RoundToInt((transform.position.y + transform.forward.y) / GridController.GridSize) * GridController.GridSize - (GridController.GridSize / 2),      // * previewCube.transform.localScale.y + previewCube.transform.localScale.y,
                                                             Mathf.RoundToInt((transform.position.z + transform.forward.z * 2) / GridController.GridSize) * GridController.GridSize - (GridController.GridSize / 2)); // * previewCube.transform.localScale.z);
            }
            else
            {
                previewCube.transform.position = new Vector3((transform.position.x + transform.forward.x * 2),
                                                             (transform.position.y + transform.forward.y),
                                                             (transform.position.z + transform.forward.z * 2));
            }
            previewCube.GetComponent <Renderer>().material.color = Colorpicker.cubeColor;
        }


        if (!GetComponent <VRTK_ControllerEvents>().triggerPressed || previewCube.GetComponent <CubeCollisionCheck>().isColliding())
        {
            return;
        }
        GameObject placedCube = Instantiate(previewCube, previewCube.transform.position, previewCube.transform.rotation) as GameObject;         // Spawn new cube on preview position

        //placedCube.transform.localScale = Vector3.one;
        placedCube.transform.SetParent(GameObject.Find("PlacedCubes").transform);
        CubeController.CubePlaced(placedCube);
        placedCube.GetComponent <Renderer>().material.color = Colorpicker.cubeColor;
        Destroy(placedCube.GetComponent <CubeCollisionCheck>());
    }