มาเริ่มกันเลยครับ
1. ให้ทำการสร้าง UI ดังรูปนะครับ (โดยทำการสร้าง Input Field สำหรับ Username & Password และ ปุ่มสำหรับ Login & Cancel)
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
public class LoginController : MonoBehaviour
{
public InputField username;
public InputField password;
// ทำการ debug ค่าที่ได้จาก Input Field
public void Login()
{
Debug.Log("Username : " + username.text);
Debug.Log("Password : " + password.text);
}
// ทำการ clear ค่า
public void ClearForm()
{
username.text = "";
password.text = "";
}
}
4. จากนั้นเลือกปุ่ม Login และหกปุ่ม + ในส่วนของ On Click() จากนั้นทำการลาก Login Script GameObject ไปยังในส่วนของ Object และ Set Function ไปยัง Login() ดังภาพ
เท่านี้ก็สามารถนำไปประยุกต์ใช้ได้แล้วครับ
ปล.มีอะไรแนะนำได้นะครับ