- Home /
Question by
unity_2020higginbothamdarby · Jun 11, 2018 at 08:33 PM ·
c#playerprefscollision2dstringstextbox
Textbox code not working
So my code here is used for switching between groups of text. It has worked before but now it decides not to and I can't figure out why I even reset all the values please help. I also have checked that the text will fit in the text boxes.
public class TextBoxScript : MonoBehaviour {
public Text text;
private bool hasTextChanged;
public bool TextStop;
private GameObject Textbox;
private Image TextBoxImage;
public string Text1;
public string Text2;
public string Text3;
public TextboxCollision TC;
public float timetowait;
public float TextboxNo;
public float PlayerprefsValue;
void Awake()
{
}
void Start()
{
text.text = "";
TextboxNo = 0;
}
//this is activated from another script which works or the text box won't even appear
public void FirstText() {
text.text = Text1;
TextboxNo = 2;
}
void Update () {
//easy value checking
PlayerprefsValue = PlayerPrefs.GetFloat ("TextBoxNo");
//this takes care of progressing the groups of text.
if (PlayerPrefs.GetFloat ("TextBoxNo") == 0) {
if (Input.GetKey (KeyCode.G) && TextboxNo == 2) {
text.text = Text2;
TextboxNo = 3;
StartCoroutine (TextHolder ());
}
if (Input.GetKey (KeyCode.G) && TextboxNo == 3 && TextStop == true) {
text.text = Text3;
TextStop = false;
StartCoroutine (TextHolder ());
TextboxNo = 4;
}
if (Input.GetKey (KeyCode.G) && TextboxNo == 4 && TextStop == true) {
TC.ExitTextBox ();
text.text = "";
}
}
}
//this stops the text from progressing too quickly
IEnumerator TextHolder () {
yield return new WaitForSeconds (timetowait);
TextStop = true;
}
}
Heres the code that has the player collide to activate FirstText
void OnCollisionEnter2D(Collision2D other) {
if (PlayerPrefs.GetFloat ("TextBoxNo") == 0) {
if (other.gameObject.name == "Player") {
BC2D.enabled = true;
TextBoxImage.enabled = true;
TBS.FirstText ();
//activate text and disable player movement and switch the text box image
TextBoxText.SetActive (true);
TextBoxImage.sprite = TextBoxSprite;
PM.enabled = false;
TextBoxCollision = true;
}
}
}
Comment