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 /
avatar image
0
Question by KatrinaMay14 · Jun 13, 2016 at 06:00 AM · unity5monodevelop

Updating a UI Text at a set rate using numbers from an array

Hello! So I'm writing a script that will display the altitude of my gameobject as it travels. I'm getting its altitude from a text file that I've put into an array. Here's my code so far:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Text;
 using System.IO;
 using System.Collections;
 using System;
 
 public class PlayerController: MonoBehaviour {
 
 
     private Vector3 position;
     private double[] nums;
     private double altDisplay;
     public Text altText;        

     void Start()
     {
         //Import text file and read all.
         string text = System.IO.File.ReadAllText("File.txt");
         if (text != null) 
         {
             //Split the string of text into an array containing each number in the file.
             string[] strings = text.Split (new[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
 
             //Convert each string number to a double.
             nums = new double[strings.Length];
             for (int i = 0; i < strings.Length; i++) 
             {
                 nums [i] = Convert.ToDouble (strings [i]);
             }
                 
         }
     }
 
     void FixedUpdate()
     {
 
         //Common variables
         int Entries = 6992;
         float speed = 1.0f;
 
         //Determine the Y altitude
         float yMeters;
 
         for (int i = 3; i < Entries; i += 7) 
         {
             yMeters = Convert.ToSingle(nums [i + 7] - nums [i]);
             transform.position += transform.up * yMeters * Time.deltaTime * speed;
         }
 
         for (int i = 3; i < 6999; i += 7) 
         {
             altText.text = (nums[i]).ToString () + "m "; 
         }
     }
 }

The reason my for loop starts at 3 and increments by 7 is because my text file has 1000 lines that look like this

x1 x2 x3 x4 x5 x6 x7

and the altitude that I need is the x4 number of each line. My problem is that when I click play, the only altitude that is displayed is the very last one. I understand that the for loop is probably running through each one very quickly, so I guess my question is: How do I get the text to update at the same rate that my gameobject is updating?

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there a way to get Unity to generate the MonoDevelop/VS solution WITHOUT actually opening it? 1 Answer

Linux Unity: Recognize dependent dll files 0 Answers

Installed 5.1, Monodevelop wont open 0 Answers

I use Ubuntu, but Monodevelop Autocomplete is not working. is there some additional Add in ? 1 Answer

Mono is being derpy help 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