I would like to set the contents of the Input Field equal to a placeholder in another script and scene, when the user presses Enter. I keep Getting an Error. The code looks fine to me, however I am new to C#.
Script #1
/*
* Project> InfCreations-IV
*/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
public class StartDisplay : MonoBehaviour
{
[Header("Start Display")]
public Text FlashingText;
public string[] stringText;
public Text Arrow;
public GameObject UserField;
public InputField input;
[SerializeField]
private Animator animator;
public float speed = 0.05f;
int StringIndex = 0;
int CharacterIndex = 0;
void Start ()
{
StartCoroutine(Transition());
UserField.SetActive(false);
}
IEnumerator Transition ()
{
Arrow.canvasRenderer.SetAlpha(0f);
while (1 == 1)
{
yield return new WaitForSeconds(speed);
FlashingText.text = stringText[StringIndex].Substring(0, CharacterIndex);
speed += Time.fixedDeltaTime;
CharacterIndex++;
if (CharacterIndex > stringText[StringIndex].Length)
{
Arrow.CrossFadeAlpha(1f, speed, false);
UserField.SetActive(true);
}
if (CharacterIndex++ == 19)
{
animator.SetTrigger("MoveUp");
yield return false;
yield break;
}
}
}
void Update()
{
if (input.text != null)
{
if (Input.GetKeyDown(KeyCode.Return))
{
StartCoroutine(LoadMainMenu());
return;
}
} else
{
return;
}
}
IEnumerator LoadMainMenu()
{
yield return new WaitForSeconds(0f);
Arrow.CrossFadeAlpha(0f, speed, false);
UserField.transform.position = new Vector3(1000, 1000, 1000);
yield return new WaitForSeconds(1f);
FlashingText.transform.position = new Vector3(1000, 1000, 1000);
SceneManager.LoadScene("Loading");
}
}
Script #2
/*
* Project> InfCreations-IV
*/
using UnityEngine;
using UnityEngine.UI;
public class Loading : MonoBehaviour
{
public Text Title;
private StartDisplay startDis;
void Start ()
{
Title = FindObjectOfType<Text>();
startDis = FindObjectOfType<StartDisplay>();
Title.text = startDis.input.text;
}
}