-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathInputExample.cs
More file actions
32 lines (28 loc) · 1.01 KB
/
Copy pathInputExample.cs
File metadata and controls
32 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System.Collections;
public class InputExample : MonoBehaviour
{
// Assign in editor
[SerializeField]
private InputField inputField = null;
[SerializeField]
private Text textDisplay = null;
// Use this for initialization
void Start()
{
// Add a Submit Event object with a listener.
/* Note: onEndEdit is called both when Submit key is pressed and when you click away from the field.
* If you want to build a larger form or not submit right away for any other reason, don't use this.
* Instead create a button that calls a function, which then reads the value of inputField.text
*/
InputField.SubmitEvent submitEvent = new InputField.SubmitEvent();
submitEvent.AddListener(OnInputSubmitted);
inputField.onEndEdit = submitEvent;
}
private void OnInputSubmitted(string value)
{
textDisplay.text = value;
}
}