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 upariver · Jun 28, 2016 at 07:50 PM · arrayoutofboundsout of bounds

Array index is out of range?

I am doing a language changing system with buttons where if you click the language you want it changes to that language. I am doing this by using different arrays for each language and when I click one of them it assigns all of the main array string's values to that language's array values.

It works, however I am getting an array out of bounds for some reason. Can anyone point me in the right direction?

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Mainscript : MonoBehaviour {
 
     public Text Test;
     public string[] names;
     public string[] Ptnames;
     public string[] LanguageHolder;
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         UpdateStrings();
     }
 
     public void changePt()
     {
         
        for(int i = 0; i <= Ptnames.Length;i++)
         {
             LanguageHolder[i] = Ptnames[i]; 
 
         }
        
 
     }
 
     public void changeEnglish()
     {
         for (int i = 0; i <= names.Length; i++)
         {
             LanguageHolder[i] = names[i];
         }
     
     }
 
     public void UpdateStrings()
     {
 
         Test.text = LanguageHolder[0];
     }
 }
 
Comment
Add comment · Show 2
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 PrisVas · Jun 28, 2016 at 08:02 PM 0
Share

Which array is getting the "out of range" error?

avatar image upariver PrisVas · Jun 28, 2016 at 08:10 PM 0
Share

Both, when I click either buttons the respective array gets out of range.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by PrisVas · Jun 28, 2016 at 08:13 PM

Try this:

  public string[] names = new string[];
  public string[] Ptnames = new string[];
  public string[] LanguageHolder = new string[];


Comment
Add comment · Show 4 · 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 upariver · Jun 28, 2016 at 08:18 PM 0
Share

Gives me an error of "Array creation must have size or array initializer"

avatar image PrisVas upariver · Jun 28, 2016 at 08:22 PM 1
Share

Oooohh I see now! Should be: "i < Ptnames.Length" and "i < names.Length"

avatar image upariver PrisVas · Jun 28, 2016 at 08:39 PM 0
Share

Oh ok that's it. $$anonymous$$any thanks! How would I do this with a resizable list ins$$anonymous$$d, if you don't $$anonymous$$d answering?

Show more comments

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

64 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[C#] Array out of bounds 1 Answer

What is the problem with the loop? 0 Answers

Storing a Gameobject from array into a Gameobject variable giving NullReferenceException 3 Answers

Fields not populated during OnValidate on Editor startup 2 Answers

Cannot convert UnityEngine.GameObject to UnityEngine.GameObject 1 Answer


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