I have a broblem with boolean (C#)(Unity)

Updated on July 22, 2018 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on July 18, 2018

I have 3 canvas and 3 buttons that make each panel visible
 
Button 1 —> Canvas 1, Button 2 —> Canvas 2, Button 3 —> Canvas 3
 
I want only one canvas visible every time, so i want every click on the button 1 to: activate canvas 1 and close canvas 2 and 3 (same for buttons 2,3)
 
this is my code:
 
[/code]

 public CanvasGroup CgUp;
 public CanvasGroup CgGe;
 public CanvasGroup CgMa;
 private bool isVisibleUp;
 private bool isVisibleGe;
 private bool isVisibleMa;
  // Canvas1 Visibility
  public void ToggleVisibilityUp ()
    {
    if (isVisibleUp == false)
    {
         CgUp.alpha = 1;
         CgGe.alpha = 0;
         CgMa.alpha. = 0;
         CgUp.interactable = true;
         CgGe.interactable = false;
         CgMa.interactable = false;
         isVisibleUp = true;
         isVisibleGe = false;
         isVisibleMa = false;
     }
     else
     {
        CgUp.alpha = 0;
        CgUp.interactable = false;
        isVisibleUp = false;
     }
     }
   
    // Canvas2 Visibility
    public void ToggleVisibilityGe ()
   {
      if (isVisibleGe == false)
   {
         CgUp.alpha = 0;
         CgGe.alpha = 1;
         CgMa.alpha. = 0;
         CgUp.interactable = false;
         CgGe.interactable = true;
         CgMa.interactable = false;
         isVisibleUp = false;
         isVisibleGe = true;
         isVisibleMa = false;
   }
   else
  {
         CgGe.alpha = 0;
         CgGe.interactable = false;
         isVisibleGe = false;
 }
}
  // Canvas3 Visibility
  public void ToggleVisibilityMa ()
    {
      if (isVisibleMa == false)
     {
         CgUp.alpha = 0;
         CgGe.alpha = 0;
         CgMa.alpha. = 1;
         CgUp.interactable = false;
         CgGe.interactable = false;
         CgMa.interactable = true;
         isVisibleUp = false;
         isVisibleGe = false;
         isVisibleMa = true;
    }
    else
   {
         CgMa.alpha. = 0;
         CgMa.interactable = false;
         isVisibleMa = false;
  }
    }
}

The problem is that when i click a button (Lest say the button 1(Canvas 1)) it doesn't turn the bool (isVisibleUp) to true but it stays false
can you help me?

  • Liked by
Reply
2 on July 18, 2018

Can I see this script in the inspector please?

on July 19, 2018
on July 19, 2018

https://prntscr.com/k8h3wb

Show more replies
  • Liked by
Reply
Cancel
0 on July 22, 2018

you need .enabled for visibility not .interactable

public void ToggleVisibilityUp()     {         
 isVisibleUp = !isVisibleUp;    
 if (isVisibleUp == false)     {      
 CgUp.alpha = 1;      
 CgGe.alpha = 0;      
 CgMa.alpha. = 0;      
 CgUp.enabled = true;      
 CgGe.enabled = false;      
 CgMa.enabled = false;      
 isVisibleGe = false;      
 isVisibleMa = false;    
 }    
 else     {      
 CgUp.alpha = 0;      
 CgUp.enabled = false;    
 }
}
  • Liked by
Reply
Cancel