void Update() { if (!isLocalPlayer) { return; } timer += Time.deltaTime; // Set color of text based on team if (unitIdentity.id == 0) { unitInfo.GetComponent <Text> ().color = Color.red; } else if (unitIdentity.id == 1) { unitInfo.GetComponent <Text> ().color = Color.blue; } // End color setting. if (health <= 0) { GameObject.Find("Canvas").transform.FindChild("Defeat").gameObject.SetActive(true); } if (isAntHillSelected) { //spawnAttackAnt.transform.FindChild("UnitInfo").GetComponent<Text>().text = " Unit: " + gameObject.name + "\n Health: " + health; unitInfo.GetComponent <Text>().text = "Unit: " + gameObject.name + " \n Health: " + health; displayAntHillInfo(); if (Input.GetKeyDown(KeyCode.Q)) // Hotkeys, q for basic ant, w for beatle unit. { spawnBasicAntUnit(); } if (Input.GetKeyDown(KeyCode.W)) { spawnBeatle(); } } else { /*spawnAttackAnt.SetActive(false); * spawnBeatleUnit.SetActive (false);*/ WorldHandler.hideAnthillInfo(); } if (cameraAntHillPos != Vector3.zero) { // when space is pressed, move camera to the anthill if (Input.GetKey(KeyCode.Space) && isAntHillSelected) { Camera.main.transform.position = cameraAntHillPos; } } }
void OnMouseDown() // Change to OnMouseHover and check for clicks, then put a public static bool inside of dragselection script called "isDragging" if you are dragging none of this should apply { if (!EventSystem.current.IsPointerOverGameObject()) // If the mouse is not over an event system object (UI Object) and the user is pressing the left click { WorldHandler.deselectUnits(); WorldHandler.deselectAntHill(); Cursor.lockState = CursorLockMode.Confined; // lock the cursor when the user clicks the terrain. WorldHandler.hideAnthillInfo(); WorldHandler.DestroyFlags(); } }