// Update is called once per frame void Update() { if (uiMode == 0) { if (spawnUnit.enabled == true) { spawnUnit.enabled = false; } if (spawnBuilding.enabled == true) { spawnBuilding.enabled = false; } if (buildStuff.enabled == true) { buildStuff.enabled = false; } } if (uiMode == 0.5f) { if (buildStuff.enabled == false) { buildStuff.enabled = true; } if (spawnUnit.enabled == true) { spawnUnit.enabled = false; } if (spawnBuilding.enabled == true) { spawnBuilding.enabled = false; } BuildingMovement checkIfBuilt = ClickingUI.Instance.previousObject.GetComponent <BuildingMovement>(); buildingProgress.text = ("Progress: " + (checkIfBuilt.percentageBuilt * 100).ToString("F0") + "%"); if (checkIfBuilt.canCreate) { uiMode = 1; } } if (uiMode == 1) { buildStuff.enabled = false; spawnBuilding.enabled = false; spawnUnit.enabled = true; if (Input.GetKeyDown(KeyCode.U)) { //spawnUnit.interactable = true; CreateUnit(ClickingUI.Instance.previousObject); } } if (uiMode == 2) { if (spawnBuilding.enabled == false) { spawnBuilding.enabled = true; } buildStuff.enabled = false; spawnUnit.enabled = false; SpencersnavAgent unitMove = ClickingUI.Instance.previousObject.GetComponent <SpencersnavAgent>(); unitMove.canMove = true; ClickingUI.Instance.builderUnit = ClickingUI.Instance.previousObject; if (Input.GetKeyDown(KeyCode.B)) { CreateBuilding(); } } }
// Update is called once per frame void Update() { // Debug.Log(uiMode); Ray placementRay = Camera.main.ScreenPointToRay(Input.mousePosition); float rayDist = 10000f; Debug.DrawRay(placementRay.origin, placementRay.direction, Color.yellow); RaycastHit placementRayHit = new RaycastHit(); if (!isClickingButton) { if (Physics.Raycast(placementRay, out placementRayHit, rayDist)) { if (placementRayHit.transform.name == "Ground") { placement = placementRayHit.point; } } if (Input.GetMouseButtonDown(0)) { Ray shootRay = Camera.main.ScreenPointToRay(Input.mousePosition); float maxRayDist = 10000f; Debug.DrawRay(shootRay.origin, shootRay.direction, Color.yellow); RaycastHit shootRayHit = new RaycastHit(); if (Physics.Raycast(shootRay, out shootRayHit, maxRayDist)) { if (shootRayHit.transform.gameObject != previousObject) { if (previousObject != null && previousObject.tag == "Unit") { SpencersnavAgent unitMove = previousObject.GetComponent <SpencersnavAgent>(); unitMove.canMove = false; } } if (shootRayHit.transform.childCount > 0) { wireframe = shootRayHit.transform.GetChild(0).GetComponentInChildren <MeshRenderer>(); } if (shootRayHit.transform.childCount == 0) { wireframe = shootRayHit.transform.GetComponent <MeshRenderer>(); } if (previousObject != null) { if (previousObject.transform.childCount > 0) { if (previousObject.transform.GetChild(0).name == "Wireframe") { if (wireframe != mostRecent && mostRecent != null) { mostRecent.enabled = false; UiController.Instance.uiMode = 0; } } } } mostRecent = wireframe; previousObject = shootRayHit.transform.gameObject; if (shootRayHit.transform.childCount > 0) { if (shootRayHit.transform.GetChild(0).name == "Wireframe") { wireframe.enabled = true; if (shootRayHit.transform.tag == "Building") { if (buildPlace != Vector3.zero) { SpencersnavAgent unitMove = builderUnit.GetComponent <SpencersnavAgent>(); unitMove.chosen = true; } BuildingMovement checkIfBuilt = previousObject.GetComponent <BuildingMovement>(); if (checkIfBuilt.canCreate) { UiController.Instance.uiMode = 1; } if (!checkIfBuilt.canCreate) { UiController.Instance.uiMode = 0.5f; } } if (shootRayHit.transform.tag == "Unit") { UiController.Instance.uiMode = 2; } } } } } } }