Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 downhilldan · Jan 29, 2017 at 12:47 PM · arraytextsavingscenesdifferent

Saving the State of Text in an Array

Hi All,

I've been trying to figure this problem out for about a week now. I'm trying to save the state of text (disabled/enabled) in an array. My problem is that the script that saves and loads my data is in my first scene and then the text that I need to be disabling/enabling is in the next scene. I cant find a way to populate the array with my text from the other scene.

My data is stored in this script along with the array of text (persists through all scenes):

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 using UnityEngine.UI;
 
 public class DataManagement : MonoBehaviour 
 {
 
     public static DataManagement datamanagement;
     [Space(10)]
     public int currentCoins;
     public int totalCoins;        
     [Space(10)]
     public int currentDistance;
     public int totalDistance;
     [Space(10)]
     public int highScore;
     [Space(10)]
     public int modelAvailibilty = 1;
 
     public Text[] pricesText;    //this is the text array that I need to populate
 
 
     void Awake () 
     {
         if (PlayerPrefs.HasKey ("CharacterSelected")) 
         {
             modelAvailibilty = PlayerPrefs.GetInt ("ModelAvailibilty");
         }
             
         if (datamanagement == null) 
         {
             DontDestroyOnLoad (gameObject);
             datamanagement = this;
         }
 
         else if (datamanagement != this)
         {
             Destroy (gameObject);
         }
     }
 
 
     public void SaveData ()
     {
         BinaryFormatter binForm = new BinaryFormatter();
         FileStream file = File.Create (Application.persistentDataPath + "/gameInfo.dat");
         gameData data = new gameData();
         data.highScore = highScore;
         data.totalCoins = totalCoins;
         data.totalDistance = totalDistance;
         data.modelAvailibilty = modelAvailibilty;
         data.pricesText = pricesText;       //text
         binForm.Serialize (file, data);
         file.Close ();
     }
 
 
     public void LoadData ()
     {
         if (File.Exists (Application.persistentDataPath + "/gameInfo.dat")) 
         {
             BinaryFormatter binForm = new BinaryFormatter ();
             FileStream file = File.Open (Application.persistentDataPath + "/gameInfo.dat", FileMode.Open);
             gameData data = (gameData)binForm.Deserialize (file);
             file.Close ();
             highScore = data.highScore;
             totalCoins = data.totalCoins;
             totalDistance = data.totalDistance;
             modelAvailibilty = data.modelAvailibilty;
             pricesText = data.pricesText;      //text
         }
     }
 }
 
 
 [Serializable]
 class gameData
 {
     public int highScore;
     public int totalCoins;
     public int totalDistance;
     public int modelAvailibilty;
     public Text[] pricesText;    //text
 }


I'm very new to programming so any help is greatly appreciated. If you need any more info on what I'm trying to accomplish exactly, please let me know! :)

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

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. 5 Answers

NeedHelp: Attempting to make a script that would play AudioClips based on Scene Index Numbers using an Array 0 Answers

Beginners question. Need help with text display on the SCENE window. 3 Answers

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 UI and Array 3 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