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 SinglePlayerPlus · Jan 23, 2019 at 08:34 PM · scripting problemarraysdialoguestrings

Any way to update a string array mid game?,Update the strings in a string array mid game?

I have a couple of dialogue scripts set up to print out text from an array, but the text doesn't update... it keeps trying to read my inactive array instead of the active one...

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(AudioSource))]
 public class TextDraw : MonoBehaviour
 {
     private DialougeManager dMan;
     public Text TextBeingEdited;
     public float Delay = 0.1f;
     private DialougeHolder dHold;
     public int AmountofLines;
     private int currentLine = 0;
     private string CurrentText = "";
     public string[] textBeingDrawn;
     public bool DialougeActive;
     public GameObject DialougeManager;
     private bool isDrawing;
     AudioSource SpeechSound;
     public bool is_menu;
     public bool ForStory;
     public bool IsActive;
 
     // Use this for initialization
     void Awake()
     {
         Debug.Log("Active Now");
         if (IsActive == true)
         {
             isDrawing = true;
             DialougeManager.SetActive(true);
             if (currentLine >= AmountofLines)
             {
                 currentLine = 0;
             }
             CurrentText = textBeingDrawn[currentLine];
             DialougeActive = true;
             SpeechSound = GetComponent<AudioSource>();
             StartCoroutine(DrawText());
         }
             
     }
 
     void Update()
     {
         if(ForStory == true)
         {
             if(currentLine >= AmountofLines)
             {
                 currentLine = 0;
                 DialougeActive = false;
                 DialougeManager.SetActive(false);
             }
         }
         if(is_menu == true)
         {
             if (Input.GetKeyDown(KeyCode.Escape))
             {
                 DialougeActive = false;
             }
         }
 
 
 
         if (is_menu == true)
         {
             if (Input.anyKeyDown && DialougeActive == true && isDrawing == false)
             {
                 currentLine++;
                 isDrawing = true;
                 StartCoroutine(DrawText());
             }
         }
         else
         {
             if (Input.GetKeyDown(KeyCode.Space) && DialougeActive == true && isDrawing == false)
             {
                 currentLine++;
                 isDrawing = true;
                 StartCoroutine(DrawText());
             }
         }
 
         if (currentLine >= AmountofLines)
         {
             DialougeActive = false;
             currentLine = 0;
             DialougeManager.SetActive(false);
         }
 
         CurrentText = textBeingDrawn[currentLine];
     }
 
     IEnumerator DrawText()
     {
         if(isDrawing == true)
         {
             for (int i = 0; i < CurrentText.Length; i++)
             {
                 CurrentText = CurrentText.Substring(0, i);
                 SpeechSound.Play();
                 TextBeingEdited.text = CurrentText;
                 yield return new WaitForSeconds(Delay);
             }
             isDrawing = false;
         }
         else
         {
             isDrawing = true;
         }
     }
 }
 


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DialougeTrigger : MonoBehaviour {
 
     public GameObject TextToTrigger;
     private TextDraw TD;
 
     void Start()
     {
         TD = TextToTrigger.GetComponent<TextDraw>();
     }
 
     // Use this for initialization
     void OnTriggerEnter2D (Collider2D other) {
         if(other.transform.tag == "Player")
         {
             Debug.Log("Entered");
             TextToTrigger.SetActive(true);
             TD.DialougeActive = true;
             TD.IsActive = true;
         }
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 }


I know the script is being read because both debug.log statements show up in the console and enabling the old array makes it read that off.

Any way to update the array after one script closes? Thanks!

Comment
Add comment · Show 1
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 xxmariofer · Jan 23, 2019 at 08:43 PM 0
Share

it is hard to know without any comments or anything, but what you are trying to achieve, what do you mean is trying to read your inactive array? you only have 1 array. Your problem is the string being shown in the text is always the same? or whats the exact problem?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SinglePlayerPlus · Jan 23, 2019 at 08:59 PM

@xxmariofer

I have the same script on two different objects. When one is disabled. I want the array to clear, so the next one that loads array is the one that shows.

Comment
Add comment · Show 8 · 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 xxmariofer · Jan 23, 2019 at 09:17 PM 0
Share

But can you open both dialogues at the same time? since you can trigger the second while still be reason the first right?

avatar image SinglePlayerPlus xxmariofer · Jan 23, 2019 at 09:20 PM 0
Share

Just tried, if they both start enabled I can trigger both at the same time, but if I trigger one later it doesn't work.

avatar image xxmariofer SinglePlayerPlus · Jan 23, 2019 at 10:19 PM 0
Share

each script has its own text? or they share it? sorry im having issues to imagine how it was implemented.

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

240 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 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 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 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

How do I Effect a whole Array of GameObjects' Scripted Boolean? 0 Answers

Cannot convert 'String' to 'Array'. 2 Answers

how to instantiate an object from an array above the previously instantiated object from the same array? 1 Answer

Delete GameObject on a specific Grid Location 1 Answer

Issue with using modulus operator with array 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