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 Gildart · Sep 29, 2015 at 07:56 PM · arraytext

Text UI and Array

Hallo, i try to display the number on the UI.

public float count;

count = 3;

SetCountText();

 void SetCountText()
 {
     countText.text="Count: "+ count;


and in the text its display 3 thats fine.

but i need to have an array so i try it with an array

public float [] count;

count[0] = 3;

SetCountText();

 void SetCountText()
 {
     countText.text="Count: "+ count[0];

and notthing happend, on the display they are written Text and not the number.

i try it with public float [] count = new float[6]; and it doesnt work.

can someone help me :) ?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by do2 · Sep 29, 2015 at 08:17 PM

Try this and post what you find out.

 void SetCountText()
  {
 Debug.Log(count[0]+""); // to ensure the variable has a value
 int C = count[0]; 
 countText.text="Count: "+ C;

this is just to test where the error is, you should be able to pass a value inside of an array with no problem.

Comment
Add comment · 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
0

Answer by Gildart · Sep 29, 2015 at 08:49 PM

Hallo Thanks for your answer, i try it but it doesnt help.

i get in the Error IndexOutOfRangeException: Array index is out of range.


public class PlayerController : MonoBehaviour {

 public Text countText;
 
 public float [] count;

void Start () {

     count[0] = 3;
     SetCountText();
 }

 void Update () 
 {
     SetCountText();
 }
 
 void SetCountText()
 {    Debug.Log(count[0]+"");
     float C = count [0];
     countText.text="Count: "+ C;
 
 }
 

}

i have also try it with int [] count; int C= count[0]; and it doesnt work.

mhmmmm :/

Comment
Add comment · 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
0

Answer by do2 · Sep 29, 2015 at 08:59 PM

Ok Mate. if you are having an IndexOutOfRangeException, then it means that you are not initializing the array correctly.

instead of

 count[0] = 3;

do

 count = new float[3];

check out the following link for the correct way to initialize and manipulate arrays in c# https://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx

specially this part

 int[] numbers; // declare numbers as an int array of any size
 numbers = new int[10];  // numbers is a 10-element array
 numbers = new int[20];  // now it's a 20-element array

Comment
Add comment · 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

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

30 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

Related Questions

Can I create a GameObject Array then fill UI text elements and then somehow use a For Loop to drop an Array of Int values inside those UI text boxes from largest to lowest? 0 Answers

Text, Dictionary, and GetComponent 1 Answer

How to get text from array or in bool? 1 Answer

How do I add 10 UI text elements to an array or a list...? 1 Answer

Help with arrays of arrays please 2 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