void OnMouseDown() { if (IsInCorrectScene()) { if (!deathManager.IsDead()) { //Avoid pointing to something with a UI element in front of it if (EventSystem.current.IsPointerOverGameObject()) { return; } //if the towerToBuild variable is null dont do anything if (buildManager.GetTowerToBuild() == null) { return; } if (tower != null) { Debug.Log("can't build there! - TODO: Display on screen."); return; } if (isAlreadBuilt == true) { return; } buildManager.DestroySelectionTowerToBuildInstance(); currentBuildingTower = buildManager.GetTowerToBuild(); soulsCounter.BuildTower(buildManager.GetTowerToBuildIndex()); scoreCounter.BuildTower(buildManager.GetTowerToBuildIndex()); GameObject[] treeArr; treeArr = GameObject.FindGameObjectsWithTag("Tree"); for (int i = 0; i < treeArr.Length; i++) { if (Vector3.Distance(treeArr[i].transform.position, transform.position) < towerDist + 1.5f) { Destroy(treeArr[i]); GameObject eff = (GameObject)Instantiate(destroyEffect, treeArr[i].transform.position, treeArr[i].transform.rotation); Destroy(eff, 2f); } } //StartCoroutine (EventInstantiator ()); mouseCursorManager.SetIdleCursor(); BuildTower(); } } }