Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a tower Defence Game. and my buttons are working fine... Until i select and unselect a tower. what I've worked out, is that after I've selected a tower the follow section of code sets my menu to the root menu every time i click a UI button, Instead of doing what the button says to do.

if(Input.GetMouseButtonDown(0)){
    if (Physics.Raycast(ray, out hit,Mathf.Infinity,pickMask)){
        if (placeableBuildingOld != null){
            placeableBuildingOld.SetSelected(false);
        }
        hit.collider.gameObject.GetComponent<PlaceableBuilding>().SetSelected(true);
        menu.selectedTurret = hit.transform.gameObject;
        placeableBuildingOld = hit.collider.gameObject.GetComponent<PlaceableBuilding>();
    }else{
        if (placeableBuildingOld != null){
            menu.selectedTurret = null;
            placeableBuildingOld.SetSelected(false);
        }
    }
}

Here is the code that it links too.

public void SetSelected(bool s){
    if (s) {
        menu.SetMenu (3, this.gameObject);
    } else {
        menu.SetMenu (0);
    }
}

What i think i need is some way for the else section to not run if i'm clicking on the UI. but for the life of me i can't think of a way to do this.

I haven't Included the SetMenu code as there is nothing wrong with that code. it works perfectly as intended, the issue is that after selecting a tower SetSelected(false) is called every time i click Anything.

I though of adding a Variable to track if something is selected before executing the else statement, and that half worked. I could again use my menu buttons after unselecting. However I could not Interact with my menu whiles a tower was selected. I.e. to upgrade that tower.

Thanks in advance for any answers.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.