public void TryPlaceObject() { // Determine final validitiy of placement option ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool valid = objectOnMouse.updateValidity(Physics.Raycast(ray, out hit, Eyesim.Scale, groundMask)); if (valid && canPlaceObject) { // If it is new object, add to sim manager if (!objectOnMouse.isInit) { if (objectOnMouse is Robot) { SimManager.instance.AddRobotToScene(objectOnMouse as Robot); } else if (objectOnMouse is WorldObject) { SimManager.instance.AddWorldObjectToScene(objectOnMouse as WorldObject); } else if (objectOnMouse is Marker) { SimManager.instance.AddMarkerToScene(objectOnMouse as Marker); } } // Place object physically objectOnMouse.PlaceObject(); objectOnMouse = null; canPlaceObject = false; isMouseOccupied = false; } }
private void Update() { if (objectOnMouse != null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Plane ground = new Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0)); float distance; if (ground.Raycast(ray, out distance)) { Vector3 hitpoint = ray.GetPoint(distance); objectOnMouse.transform.position = new Vector3(hitpoint.x, 0.03f, hitpoint.z); } bool valid = objectOnMouse.updateValidity(Physics.Raycast(ray, out hit, 1000f, groundMask)); if (Input.GetMouseButtonDown(0) && valid) { PlaceObject(); } } }