- Home /
[SOLVED] InputField inputted text will not show up when it is called to show up in a text object?
Hi there! I'm very, very new, so please be aware, that I'm probably going to ask some pretty dumb questions haha. I also don't really know how to format this post, so please bear with me sweatdrop
In my game, the player is prompted to type in their name in an InputField. I have the name the player types is saved as playerName.
Then, when the player clicks a button, they are directed to a different canvas with a Text object that's text needs to state. The Text object is called playernameisawesome.
When the canvas with the InputField is disabled, and the one showing the playernameisawesome text object is enabled, the player's inputted name should show. But it's not, and I'm confuzzled as to why it isn't working. Any tips?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class Name : MonoBehaviour
{
public Button LetsGo;
public Canvas TYNC;
public Canvas GC;
public TMP_InputField inputField;
public GameObject entername;
public GameObject SecondSceneManager;
public TMP_Text playernameisawesome;
public TMP_Text nameDisplay;
string playerName;
private Animation anim;
public void Start()
{
LetsGo.interactable = false;
GC.enabled = false;
}
public void ClickLetsGo()
{
TYNC.enabled = false;
GC.enabled = true;
}
public void GetInput(string playerName)
{
Debug.Log("You entered, " + playerName + ".");
nameDisplay.text = "Welcome, " + playerName + "!";
if (string.IsNullOrEmpty(inputField.text))
{
Debug.Log("Please input a name");
LetsGo.interactable = false;
nameDisplay.enabled = false;
}
else if (string.IsNullOrWhiteSpace(inputField.text))
{
Debug.Log("Please input a valid name");
LetsGo.interactable = false;
nameDisplay.enabled = false;
}
else
{
LetsGo.interactable = true;
nameDisplay.enabled = true;
if (nameDisplay.enabled == true)
{
anim.Play("Name Display Up Down");
Debug.Log("Animation is playing");
}
}
if (GC.enabled == true)
{
Debug.Log("ahhh");
playernameisawesome.text = playerName + "IS AWESOME";
}
}
}
Answer by catherinederivaledu · Jul 22, 2020 at 01:45 AM
I solved this recently! I think there was something up with the way I had the if-else functions arranged! I moved the function upwards and that seemed to solve everything for some reason!