void PlaceObject() { if (hasObj) { UpdateMousePosition(); Node curNode = gridGenerator.NodeFromWorldPosition(mousePosition); worldPosition = curNode.vis.transform.position; if (cloneObj == null) { cloneObj = Instantiate(objToPlace, worldPosition, Quaternion.identity) as GameObject; objProperties = cloneObj.GetComponent <CreateLevel> (); } else { cloneObj.transform.position = worldPosition; if (Input.GetMouseButton(0) && !ui.mouseOverUIElement) { if (curNode.placedObj != null) { manager.inSceneGameObjects.Remove(curNode.placedObj.gameObject); Destroy(curNode.placedObj.gameObject); curNode.placedObj = null; } GameObject actualObjPlaced = Instantiate(objToPlace, worldPosition, cloneObj.transform.rotation) as GameObject; CreateLevel placedObjProperties = actualObjPlaced.GetComponent <CreateLevel> (); placedObjProperties.gridPosX = curNode.nodePosX; placedObjProperties.gridPosZ = curNode.nodePosZ; curNode.placedObj = placedObjProperties; manager.inSceneGameObjects.Add(actualObjPlaced); curNode.isWalkable = false; } if (Input.GetMouseButtonUp(1)) { objProperties.ChangeRotation(); } } } else { if (cloneObj != null) { Destroy(cloneObj); } } }
void PlaceStackedObjs() { if (placeStackObj) { UpdateMousePosition(); Node curNode = gridGenerator.NodeFromWorldPosition(mousePosition); worldPosition = curNode.vis.transform.position; if (stackCloneObj == null) { stackCloneObj = Instantiate(stackObjToPlace, worldPosition, Quaternion.identity) as GameObject; stackObjProperties = stackCloneObj.GetComponent <CreateLevel>(); } else { stackCloneObj.transform.position = worldPosition; if (Input.GetMouseButtonUp(0) && !ui.mouseOverUIElement) { GameObject actualObjPlaced = Instantiate(stackObjToPlace, worldPosition, stackCloneObj.transform.rotation) as GameObject; CreateLevel placedObjProperties = actualObjPlaced.GetComponent <CreateLevel>(); placedObjProperties.gridPosX = curNode.nodePosX; placedObjProperties.gridPosZ = curNode.nodePosZ; curNode.stackedObjs.Add(placedObjProperties); manager.inSceneStackObjects.Add(actualObjPlaced); curNode.isWalkable = false; } if (Input.GetMouseButtonUp(1)) { stackObjProperties.ChangeRotation(); } } } else { if (stackCloneObj != null) { Destroy(stackCloneObj); } } }