Beispiel #1
0
        void Update()
        {
            Vector3    pos;
            Ray        r = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // get mouse position
            if (Physics.Raycast(r, out hit, 10000.0f))
            {
                if (!marker.gameObject.activeSelf)
                {
                    marker.gameObject.SetActive(true);
                }
                pos = hit.point - hit.normal * 0.5f;
                bool wantToBuild     = Input.GetButtonDown("Fire1");
                bool wantToDelete    = Input.GetButtonDown("Fire2");
                bool wantToMakeSlope = Input.GetKeyDown(KeyCode.F);
                // interaction!
                if (wantToDelete)
                {
                    ChangeVoxel(Position3.FlooredVector(pos), new Voxel(0));                     // REMOVE
                }
                else if (wantToBuild)
                {
                    ChangeVoxel(Position3.FlooredVector(pos) + Position3.RoundedVector(hit.normal), new Voxel(2));                     // ADD
                }
                else if (wantToMakeSlope)
                {
                    ChangeVoxel(Position3.FlooredVector(pos) + Position3.RoundedVector(hit.normal), new Voxel(10));                     // ADD
                }
                pos             = hit.point + hit.normal * 0.5f;
                pos.x           = Mathf.Floor(pos.x) + 0.5f;
                pos.y           = Mathf.Floor(pos.y) + 0.5f;
                pos.z           = Mathf.Floor(pos.z) + 0.5f;
                marker.position = pos;
            }
            else
            {
                if (marker.gameObject.activeSelf)
                {
                    marker.gameObject.SetActive(false);
                }
            }
        }
Beispiel #2
0
        //

        void OnGUI()
        {
            GUI.Label(new Rect(10, 10, 300, 200), "Pos: " + Position3.FlooredVector(marker.position) + "\nMove with Mouse MB\nCreate with LB\nRemove with RB");
        }