Quantcast
Channel: Answers by "ThePersister"
Viewing all articles
Browse latest Browse all 99

Answer by ThePersister

$
0
0
Hey @Fahryem, I actually found another issue with this idea, silly of me to only realise it now. Whilst the second textbox is inactive, its update won't be called. So forget what I've said before! You should probably add a third seperate class that's sitting around on another object in the scene. With this code: using UnityEngine; using System.Collections; public class TextBoxManager : MonoBehaviour { public static TextBoxManager Instance; void Awake() { Instance = this; } public GameObject m_mainTextBox; public GameObject m_otherTextBox; // Made them private, since you only really have to call the methods. private bool m_showAnyTextbox = true; // True by default. private bool m_showingMain = true; // True by default. // Initialize the textboxes just to be sure. void Start() { _updateTextBoxes(); } // Alternates between Main and Other textbox. public void ToggleTextBoxes() { m_showingMain = !m_showingMain; _updateTextBoxes(); } // Alternates between having any textbox shown or none. public void ToggleAll() { m_showAnyTextbox = !m_showAnyTextbox; _updateTextBoxes(); } // Update call for the textboxes. (No need to keep calling this in update). private void _updateTextBoxes() { m_mainTextBox.SetActive( m_showingMain && m_showAnyTextbox ); m_otherTextBox.SetActive( !m_showingMain && m_showAnyTextbox ); } } And then, anywhere in your code you can call...: TextBoxManager.Instance.ToggleAll(); // OR TextBoxManager.Instance.ToggleTextBoxes(); ....to achieve what you want! I hope this code helps you out better, sorry for not having tested the previous suggestions before, haha! Best of luck!

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>