Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I replace these two functions with a bool argument here?

Discussion in 'Scripting' started by Zody123, Jul 8, 2020.

  1. Zody123

    Zody123

    Joined:
    Jun 23, 2020
    Posts:
    4
    I'm trying to figure out how to add a bool argument to my code here instead of having both the enableButton and disableButton functions here.

    Code (CSharp):
    1.  
    2. //enable button function
    3. private void enableButton (string x)
    4. {
    5.     timerButton.interactable = true;
    6.     timeLabel.text = x;
    7. }
    8.  
    9. //disable button function
    10. private void disableButton(string x)
    11. {
    12.     timerButton.interactable = false;
    13.     timeLabel.text = x;
    14. }
    15.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Code (CSharp):
    1. private void configureButton(string x, bool interactable)
    2. {
    3.     timerButton.interactable = interactable;
    4.     timeLabel.text = x;
    5. }
     
    Zody123 likes this.
  3. Zody123

    Zody123

    Joined:
    Jun 23, 2020
    Posts:
    4
    Thank you!