public void OnClick() { if (FloorPlacementController.thingToPlace != null) { Destroy(FloorPlacementController.thingToPlace.gameObject); } if (MoneyManager.CanAfford(prefab.GetComponent <AbstractPlacedItem>())) { FloorPlacementController.thingToPlace = Instantiate(prefab).GetComponent <AbstractPlacedItem>(); Assert.IsTrue(FloorPlacementController.thingToPlace != null); } }
private void Update() { if (draggingUICopy.gameObject.activeSelf || draggingModelCopy.gameObject.activeSelf) { draggingUICopy.position = Input.mousePosition; Vector3 worldPos = Camera.main.ScreenToWorldPoint(draggingUICopy.position) - Camera.main.transform.forward * 100f; RaycastHit hit; if (Physics.Raycast(worldPos, Camera.main.transform.forward, out hit, Mathf.Infinity, 1 << groundLayerNumber)) { draggingUICopy.gameObject.SetActive(false); Vector3 finalPos = worldPos + Camera.main.transform.forward * hit.distance; draggingModelCopy.position = finalPos; draggingModelRange.position = finalPos; draggingModelCopy.gameObject.SetActive(true); if (moneyManager.CanAfford(price) && Physics.OverlapSphere(finalPos, towerSize, 1 << obstacleLayerNumber).Length == 0) { validPosition = true; draggingModelRange.GetComponent <MeshRenderer>().material = plazableMaterial; draggingModelCopy.GetComponent <MeshRenderer>().materials = towerPlazableMaterials; if (setChildMaterials) { draggingModelCopy.GetChild(0).GetComponent <MeshRenderer>().materials = towerChildPlazableMaterials; } } else { validPosition = false; draggingModelRange.GetComponent <MeshRenderer>().material = dragUnplazableMaterial; draggingModelCopy.GetComponent <MeshRenderer>().materials = towerUnplazableMaterials; if (setChildMaterials) { draggingModelCopy.GetChild(0).GetComponent <MeshRenderer>().materials = towerChildUnplazableMaterials; } } draggingModelRange.gameObject.SetActive(true); } else { draggingModelCopy.gameObject.SetActive(false); draggingModelRange.gameObject.SetActive(false); draggingUICopy.gameObject.SetActive(true); } } }
protected void Update() { if (thingToPlace != null) { if (Input.GetButtonDown("Rotate")) { var from = thingToPlace.transform.rotation.eulerAngles; thingToPlace.transform.rotation = Quaternion.Euler(from.x, from.y + 90, from.z); } if (Input.GetMouseButtonDown(1)) { Destroy(thingToPlace.gameObject); thingToPlace = null; } } if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { var hit = GetMouseHit(); if (hit != null) { var itemAtLocation = Grid.GetItem(hit.Value.point); if (thingToPlace != null && itemAtLocation == null) { if (MoneyManager.Buy(thingToPlace)) { if (MoneyManager.CanAfford(thingToPlace)) { var thingToReallyPlace = Instantiate(FloorPlacementController.thingToPlace); Grid.PlaceItem(thingToReallyPlace); thingToReallyPlace.OnConnectionChange(); onPlaceSound.Play(); } else { Destroy(thingToPlace); thingToPlace = null; } } else { Destroy(thingToPlace); thingToPlace = null; } } else if (thingToPlace == null && itemAtLocation != null) { itemAtLocation.OnClick(); } if (itemAtLocation != null) { foreach (var item in Grid.items) { if (item != null) { item.OnConnectionChange(); } } } } } } if (thingToPlace != null) { thingToPlace.OnConnectionChange(); } }