Array index is out of range. error
this is my code : public class MainMenu_script1 : MonoBehaviour {
//This public variable will hold a reference to your button image.
public Texture2D signOutButton;
public Texture2D[] buttonTextures;
private float buttonWidth;
private float buttonHeight;
void OnGUI(){
for (int i = 0; i < 2; i++) {
===> if (GUI.Button (new Rect ((float)Screen.width * 0.5f - (buttonWidth / 2),
(float)Screen.height * (0.6f + (i * 0.2f)) - (buttonHeight / 2),
buttonWidth , buttonHeight), buttonTextures[i])) {
Debug.Log("Mode " + i + " was clicked!");
if (i == 0) {
// Single player mode!
RetainedUserPick_script.Instance.multiplayerGame = false;
//Application.LoadLevel("PickCarMenu");
} else if (i == 1) {
RetainedUserPick_script.Instance.multiplayerGame = true;
MultiplayerController_script.Instance.SignInAndStartMPGame();
}
}
}//end of for()
/*This code checks if there is currently a signed-in user; if so,
* it displays a button to sign the user out. If the player taps that button,
* the app calls SignOut() on your MultiplayerController_script.
*/
if (MultiplayerController_script.Instance.IsAuthenticated()) {
if (GUI.Button(new Rect(Screen.width - (buttonWidth * 0.75f),
Screen.height - (buttonHeight * 0.75f),
buttonWidth * 0.75f,
buttonHeight * 0.75f),signOutButton))
{
MultiplayerController_script.Instance.SignOut();
}
}//end of if MultiPlayerController_script
MultiplayerController_script.Instance.SignInAndStartMPGame();
}//end of OnGUI();
// Use this for initialization
void Start () {
// I know that 301x55 looks good on a 660-pixel wide screen, so we can extrapolate from there
buttonWidth = 301.0f * Screen.width / 660.0f;
buttonHeight = 55.0f * Screen.width / 660.0f;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
MultiplayerController_script.Instance.TrySilentSignIn();
}//end of Start();
}//end of class
it show me the error on the first If statment on for loop could anyone help me hhow can I fix it ?
Comment
Best Answer
Answer by Suddoha · Sep 17, 2015 at 10:50 PM
Apparently, buttonTextures does not have enough items. Are you sure it's properly assigned in the inspector?
yeah I wasn't assigned it in the buttonTexture in the unity engine thank u for the help :D
Your answer
Follow this Question
Related Questions
Player Movement - Not moving at all 3 Answers
Kinect unity connection 0 Answers
Run Unity with X11/Xorg on Debian 0 Answers
Does it work well on an AMD CPU? 0 Answers
Player falls through terrain walls? 0 Answers