private void Update() { if (Input.GetKeyDown(KeyCode.R)) //rotate { previewGameObject.transform.Rotate(0, 90f, 0); //rotate the preview 90 degrees. You can add in your own value here } if (Input.GetKeyDown(KeyCode.G))//cancel build { CancelBuild(); } if (Input.GetMouseButtonDown(0) && isBuilding)//actually build the thing in the world { if (previewScript.GetSnapped()) { StopBuild(); } else { Debug.Log("Not Snapped");//this part isn't needed, but may be good to give your player some feedback if they can't build } } if (isBuilding) { if (pauseBuilding) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); if (Mathf.Abs(mouseX) >= stickTolerance || Mathf.Abs(mouseY) >= stickTolerance) { pauseBuilding = false; } } else { DoBuildRay(); } } }
private bool pauseBuilding = false; //used to pause the raycast private void Update() { if (Input.GetKeyDown(KeyCode.R)) //rotate { previewGameObject.transform.Rotate(0, 90f, 0); //rotate the preview 90 degrees. You can add in your own value here } if (Input.GetKeyDown(KeyCode.G))//cancel build { CancelBuild(); } if (Input.GetMouseButtonDown(0) && isBuilding) //actually build the thing in the world { if (previewScript.GetSnapped()) //is the previewGameObject currently snapped to anything? { StopBuild(); //if so then stop the build and actually build it in the world } else { Debug.Log("Not Snapped");//this part isn't needed, but may be good to give your player some feedback if they can't build } } if (isBuilding) { if (pauseBuilding) //is the build system currently paused? if so then you need to check deviation in the mouse { float mouseX = Input.GetAxis("Mouse X"); //get the mouses horizontal movement..these may be different on your copy of unity float mouseY = Input.GetAxis("Mouse Y"); //get the mouses vertical movement..these may be different on your copy of unity if (Mathf.Abs(mouseX) >= stickTolerance || Mathf.Abs(mouseY) >= stickTolerance) //check if mouseX or mouseY is greater than stickTolerance { pauseBuilding = false; //if it is, then unpause building, and call the raycast again } } else//if building system isn't paused then call the raycast { DoBuildRay(); } } }
private void Update() { /*if (Input.GetKeyDown(KeyCode.R) && isBuilding)//rotate * { * previewGameObject.transform.Rotate(0, 90f, 0);//rotate the preview 90 degrees. You can add in your own value here * }*/ if (Input.GetKeyDown(KeyCode.V)) { isDestroyingBuilding = true; } if (Input.GetKeyDown(KeyCode.C)) { isDestroyingBuilding = false; aimedAt.GetComponent <Structure>().ChangeColor(false); } if (Input.GetKeyDown(KeyCode.G) && isBuilding)//cancel build { CancelBuild(); } if (Input.GetMouseButtonDown(0) && isBuilding) //actually build the thing in the world { if (previewScript.GetSnapped()) //is the previewGameObject currently snapped to anything? { StopBuild(); //if so then stop the build and actually build it in the world } else { Debug.Log("Not Snapped");//this part isn't needed, but may be good to give your player some feedback if they can't build } } if (Input.GetMouseButtonDown(0) && isDestroyingBuilding) { if (aimedAt != null) { DestroyBuilding(); } else { Debug.Log("Aim at something"); } } if (isBuilding) { if (pauseBuilding) //is the build system currently paused? if so then you need to check deviation in the mouse { float mouseX = Input.GetAxis("Mouse X"); //get the mouses horizontal movement..these may be different on your copy of unity float mouseY = Input.GetAxis("Mouse Y"); //get the mouses vertical movement..these may be different on your copy of unity if (Mathf.Abs(mouseX) >= stickTolerance || Mathf.Abs(mouseY) >= stickTolerance) //check if mouseX or mouseY is greater than stickTolerance { pauseBuilding = false; //if it is, then unpause building, and call the raycast again } } else//if building system isn't paused then call the raycast { DoBuildRay(); } } if (isDestroyingBuilding) { DoDestroyBuildingRay(); } ////////////////////////////////////////////// if (Input.GetKey(KeyCode.R) && isFurniturePlacement && previewFurnitureScript.canRotate) //rotate { previewFurnitureGameObject.transform.Rotate(0, Time.deltaTime * previewRotationSpeed, 0); //rotate the preview x degrees. You can add in your own value here } if (Input.GetKey(KeyCode.T) && isFurniturePlacement && previewFurnitureScript.canRotate) //rotate { previewFurnitureGameObject.transform.Rotate(0, -Time.deltaTime * previewRotationSpeed, 0); //rotate the preview -x degrees. You can add in your own value here } if (Input.GetKeyDown(KeyCode.Q) && isFurniturePlacement && previewFurnitureScript.canRotate && previewFurnitureScript.isSnapped) //rotate { previewFurnitureScript.snappedTo.transform.Rotate(0, 90, 0); //rotate the preview 90 degrees. You can add in your own value here } if (Input.GetKeyDown(KeyCode.G) && isFurniturePlacement) //cancel build { CancelFurniturePlacement(); } if (Input.GetMouseButtonDown(0) && isFurniturePlacement)//actually build the thing in the world { if (previewFurnitureScript.CanPlace()) { PlaceFurniture(); } else { Debug.Log("Cannot place"); } } if (isFurniturePlacement) { if (pauseFurniturePlacement) //is the build system currently paused? if so then you need to check deviation in the mouse { float mouseX = Input.GetAxis("Mouse X"); //get the mouses horizontal movement..these may be different on your copy of unity float mouseY = Input.GetAxis("Mouse Y"); //get the mouses vertical movement..these may be different on your copy of unity if (Mathf.Abs(mouseX) >= stickTolerance || Mathf.Abs(mouseY) >= stickTolerance) //check if mouseX or mouseY is greater than stickTolerance { pauseFurniturePlacement = false; //if it is, then unpause building, and call the raycast again } } else//if building system isn't paused then call the raycast { DoFurniturePlacementRay(); } } }