void Update() { // Determines what the player clicked on if (Input.GetMouseButtonDown(0)) { Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(Ray, out _raycastHit)) { LastClickedObject = _raycastHit.transform.collider.gameObject; GridPoint maybeClicked = LastClickedObject.GetComponent<GridPoint>(); if(maybeClicked!=null && maybeClicked.CanBuild()){ if(lastClickedGridPoint!=null){ lastClickedGridPoint.Deselect(); } lastClickedGridPoint = maybeClicked; lastClickedGridPoint.Select(); } } } //Determine which tower to make for(int i = 0; i<TowerTypes.Length; i++){ if(Input.GetKeyDown(towerkeys[i])){ Tower t = TowerTypes[i].GetComponent<Tower>(); if(lastClickedGridPoint.CanBuild() && Global.Instance.CanBuild(t) && !lastClickedGridPoint.HasTower()){ //TODO; build tower sound lastClickedGridPoint.CreateTower(Global.Instance.CreateTower(TowerTypes[i], lastClickedGridPoint.transform.position+Vector3.up)); } else if(lastClickedGridPoint.HasTower()){ //TODO; make can't make tower sound lastClickedGridPoint.DestroyTower(); lastClickedGridPoint.CreateTower(Global.Instance.CreateTower(TowerTypes[i], lastClickedGridPoint.transform.position+Vector3.up)); } else{ //TODO; Didn't work sound } } } }