คราวนี้เรามาทำการเล่น Animation ให้กับตังละครกับ โดยปกติ PlayMaker จะไม่ซับพอร์ต Mecamin แต่บทความนี้จะใช้ Mecanim เป็นหลักนะครับ โดยเริ่มจาก Attack Animation เพื่อที่จะเอาไปใช้ประยุกต์ Animation อื่นๆ นะครับ
** หมายเหตุ ให้ทำการ Add Animator Component และ Add Animator Controller ให้กับตัวละครด้วยนะครับ
มาเริ่มกันเลย
1. ให้ทำการเลือกตัวละคร จากนั้นให้ทำการสร้าง FMS (CombatFMS) อันใหม่ขึ้นมานะครับ
2. ที่ State1 ให้ตั้งชื่อว่า Wait For Attack Input จากนั้นทำการ Add Action Get Mouse Button (Input -> Get Mouse Button)
3. ในส่วนของ Action Get Mouse Button Down ให้ตั้งค่า
- Button = Left
- Send Event = FINISHED
5. ให้ทำการสร้าง C# Script (PlayerController.cs) และทำการเพิ่มดังนี้
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
private Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
public void SetAttackAnimation()
{
animator.SetTrigger("Attack");
}
}
7. กลับมาที่ Call Method Action ให้ทำการ Set ค่า ดังรูป
- Behaviour = PlayerController Script (ลาก Script จาก Player ไปที่ช่อง)
- Method Name = SetAttackAnimation (ชื่อ Method ที่ตั้งใน Script)
เท่านี้ก็สามารถนำไปประยุกต์ใช้ในกรณีอื่นๆได้แล้วครับ
ปล. มีอะไรแนะนำได้นะครับ