Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by SooOooS · Sep 17, 2015 at 10:32 PM · unity5

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SooOooS · Sep 21, 2015 at 03:17 PM 0
Share

yeah I wasn't assigned it in the buttonTexture in the unity engine thank u for the help :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges