Button locking/unlocking for loop using an object array & playerprefs
So I have an array of buttons, this script at the start function uses a for loop defines player pref integers for the buttons in the array, 1 being intaractable and 0 being locked. button0 should be interactable and 1-14 should be locked, the problem is it's not. And again at the update function uses a for loop toggles interactable depending on if the button has a 1 or 0.
Here's the code:
 void start () {
 
 for (int i = 0; i < buttons.Length; i++) {
 
             if (PlayerPrefs.GetInt("button" + 0) == null) {
 
                 PlayerPrefs.SetInt("button" + 0, 1);
 
             }
 
             if (PlayerPrefs.GetInt("button" + i) == null) {
 
                 PlayerPrefs.SetInt("button" + i, 0);
 
             }
 
         }
 
 }
The indenting's weird here.
 void Update () {
 
         for (int i = 0; i < buttons.Length; i++) {
 
             if (PlayerPrefs.GetInt("button" + i) == 0) {
 
                 buttons[i].interactable = false;
 
             } else if (PlayerPrefs.GetInt("button" + i) == 1) {
 
                 buttons[i].interactable = true;
 
             }
 
         }
 
     }
-Please help
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by HarveyPA · Oct 23, 2016 at 11:44 PM
It was answered by some1 else, tyvm :)
The answer had something to do with how I was checking/unchecking the booleon. And the fact that integers can't be null :)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                