มาเริ่มกันเลย
1. ให้เราทำการ Import CrossPlatformInput เข้ามาใน Project
3. สร้าง HUD (ผมใช้จากตัวอย่าง Frame Debug กับ Unity GUI)
7. ในส่วนของปุ่ม Fire ก็ให้ทำการ Add Script Button Handler ครับ และตั้งชื่อ Parameter Name เป็น "Fire" และทำการ Add Event Trigger Component จากนั้นให้ทำการ Add Pointer Down และ Pointer Up และลาก ปุ่มยิงที่ทำการใส่ Script แล้วไว้ในทั้ง 2 Event และ Set Function ดังรูป
public class MobileController : MonoBehaviour
{
private Vector3 moveDirection = Vector3.zero;
void Update()
{
moveDirection = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal"), 0,
CrossPlatformInputManager.GetAxis("Vertical"));
Debug.Log(moveDirection);
if (CrossPlatformInputManager.GetButton("Fire"))
{
Debug.Log("Fire");
}
}
}
10. ทดสอบรันเกมได้เลยครับ ผลลัพธ์ตามรูป
ปล. มีอะไรแนะนำได้นะครับ
NO GAME NO DREAM !!!