public void CancelFurniturePlacement()//you no longer want to build, this will get rid of the previewGameObject in the scene { Destroy(previewFurnitureGameObject); previewFurnitureGameObject = null; previewFurnitureScript = null; isFurniturePlacement = false; DisableFurnitureSnapPoints(); }
///////////////////////////////// \|/ furniture placement /// there should be 3 modes for furniture(furniture include all nonstructure objects like shelfs, lamps and even doors or windows) /// mode 1 with snap points /// mode 2 free placement on foundation /// mode 3 free placement on other structures like walls and so on /// //////////////////////////////////////////////////////// /// public void NewFurniture(GameObject prev) { EnableFurnitureSnapPoints(); previewFurnitureGameObject = Instantiate(prev, Vector3.zero, Quaternion.identity); previewFurnitureScript = previewFurnitureGameObject.GetComponent <furniturePreview>(); previewFurnitureScript.canPlace = false; previewFurnitureScript.isSnapped = false; previewFurnitureScript.ChangeColor(); isFurniturePlacement = true; }
public void PlaceFurniture() { previewFurnitureScript.Place(); Debug.Log(uiController.activeQuickSlot + 200); inventory.RemoveBySlotId(uiController.activeQuickSlot + 200); uiController.changePickedQuickSlot(-1); previewFurnitureGameObject = null; previewFurnitureScript = null; isFurniturePlacement = false; DisableFurnitureSnapPoints(); }
private void DoFurniturePlacementRay() //actually positions your previewGameobject in the world { Ray ray = cam.ScreenPointToRay(new Vector3((Screen.width / 2), (Screen.height / 2))); //raycast stuff RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, layer))//notice the layer { if (hit.collider != null) { furniturePreview _furniturePreview = previewFurnitureGameObject.GetComponent <furniturePreview>(); Debug.Log(hit.collider.tag); // Add a tag to your object and use use CompareTag for better performace. if (hit.collider.CompareTag("Foundation") && !previewFurnitureScript.shouldBeSnapped) { previewFurnitureGameObject.transform.position = hit.point; previewFurnitureScript.isSnapped = false; previewFurnitureScript.canPlace = true; } else if (hit.collider.CompareTag("Foundation") && previewFurnitureScript.shouldBeSnapped) { previewFurnitureGameObject.transform.position = hit.point; previewFurnitureScript.isSnapped = false; previewFurnitureScript.canPlace = false; } /*else if ((hit.collider.CompareTag("Door_SP") && previewFurnitureGameObject.name == "door_preview(Clone)")) * { * previewFurnitureScript.snappedTo = hit.collider.gameObject; * previewFurnitureScript.isSnapped = true; * previewFurnitureScript.ChangeColor(); * Vector3 pos = new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z); * previewFurnitureGameObject.transform.rotation= hit.collider.transform.rotation; * previewFurnitureGameObject.transform.position = pos; * } * else if ((hit.collider.CompareTag("WallLight_SP") && previewFurnitureGameObject.name == "WallLight_Preview(Clone)")) * { * previewFurnitureScript.snappedTo = hit.collider.gameObject; * previewFurnitureScript.isSnapped = true; * previewFurnitureScript.ChangeColor(); * Vector3 pos = new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z); * previewFurnitureGameObject.transform.rotation = hit.collider.transform.rotation; * previewFurnitureGameObject.transform.position = pos; * } * else if ((hit.collider.CompareTag("CeilingLight_SP") && previewFurnitureGameObject.name == "CeilingLight_Preview(Clone)")) * { * previewFurnitureScript.snappedTo = hit.collider.gameObject; * previewFurnitureScript.isSnapped = true; * previewFurnitureScript.ChangeColor(); * Vector3 pos = new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z); * previewFurnitureGameObject.transform.rotation = hit.collider.transform.rotation; * previewFurnitureGameObject.transform.position = pos; * }*/ else { previewFurnitureGameObject.transform.position = hit.point; previewFurnitureScript.isSnapped = false; previewFurnitureScript.canPlace = false; } for (int i = 0; i < _furniturePreview.tagsISnapTo.Count; i++) { Debug.Log(i); if (_furniturePreview.tagsISnapTo[i] == hit.collider.tag) { previewFurnitureScript.snappedTo = hit.collider.gameObject; previewFurnitureScript.isSnapped = true; previewFurnitureScript.ChangeColor(); Vector3 pos = new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z); previewFurnitureGameObject.transform.rotation = hit.collider.transform.rotation; previewFurnitureGameObject.transform.position = pos; } } } } }