|
|
| 行1: |
行1: |
| − | ==人型アセットのDL==
| + | [[Unity/3d/アニメーション/基本]] |
| − | #AssetStoreからZonbie ( https://assetstore.unity.com/packages/3d/characters/humanoids/zombie-30232?locale=ja-JP ) をダウンロード
| + | |
| − | #それをimport
| + | |
| − | #PrefubからZonbie1をヒエラルキーにドラッグ
| + | |
| − | #Assetsの下にAnimetionsのdirを作成しCreate/AnimatorControllerを作成
| + | |
| − | #例として、ZonbieAnimatorControllerとして作成
| + | |
| − | #Zonbie1のanimetorにPrefubのAnimattionsのZonbie~を全てZonbieAnimatorController上へドラッグして入れる
| + | |
| − | #defaultをZ_Idolを設定
| + | |
| − | #parameterにfloatのSpeedを設定する
| + | |
| − | #Z_IdolでMakeTransitionからZ_WalkへSpeed>0.1で設定する
| + | |
| − | #zonbieオブジェクトに以下csをアタッチする
| + | |
| | | | |
| − | ZonbieController.cs
| + | [[Unity/3d/アニメーション/追いかけてくる]] |
| − | <pre>
| + | |
| − | using UnityEngine.AI;
| + | |
| − | [RequireComponent(typeof(Animator))] | + | |
| − | public class EnemyController : MonoBehaviour
| + | |
| − | {
| + | |
| − | Animator animator;
| + | |
| − | void Start()
| + | |
| − | {
| + | |
| − | animator = GetComponent<Animator>();
| + | |
| − | }
| + | |
| − | void Update()
| + | |
| − | {
| + | |
| − | animator.SetFloat("Speed", 0.2f, 0.1f, Time.deltaTime);
| + | |
| − | }
| + | |
| − | }
| + | |
| − | </pre>
| + | |
| − | | + | |
| − | | + | |
| − | 参考:https://unity.moon-bear.com/zombie-slayer/enemy-animation/
| + | |
| − | | + | |
| − | ==キーボード入力でアニメーションを追加==
| + | |
| − | #上で作った、ZonbieAnimatorControllerにZ_Attackを追加
| + | |
| − | #parameterにtriggerのAttackを設定する
| + | |
| − | #Z_IdolでMakeTransitionからZ_AttackへプロパティAttackを設定する
| + | |
| − | #以下をcsへ追加
| + | |
| − | | + | |
| − | <pre>
| + | |
| − | void Update()
| + | |
| − | {
| + | |
| − | if (Input.GetKey(KeyCode.Space))
| + | |
| − | {
| + | |
| − | animator.SetTrigger("Attack");
| + | |
| − | }
| + | |
| − | }
| + | |
| − | </pre>
| + | |
| − | スペースを押した時に攻撃モーションが表示される。
| + | |
| − | | + | |
| − | ===他キーボード===
| + | |
| − | if (Input.GetKey(KeyCode.UpArrow)) {
| + | |
| − | } else if (Input.GetKey(KeyCode.UpArrow)) {
| + | |
| − | } else if (Input.GetKey(KeyCode.LeftArrow)) {
| + | |
| − | } else if (Input.GetKey(KeyCode.RightArrow)) {
| + | |
| − | | + | |
| − | ==動作を全体座標に適用==
| + | |
| − | Apply Root Motionにチェックを入れる
| + | |
| − | | + | |
| − | ==アクション途中で遷移==
| + | |
| − | Transition/InspectorのHas Exit Timeを外す
| + | |
| − | | + | |
| − | ==オブジェクト接触判定==
| + | |
| − | #PlayerのGameObjectのInspectorのTagにPlayerを追加
| + | |
| − | #敵オブジェクトにAddComponentでCapsuleColliderを追加
| + | |
| − | #的オブジェクトにAddComponentでRigidbodyを追加
| + | |
| − | #csに以下のようにOnCollisionEnterを追加
| + | |
| − | | + | |
| − | <pre>
| + | |
| − | public class EnemyController : MonoBehaviour
| + | |
| − | {
| + | |
| − | Animator animator;
| + | |
| − | CapsuleCollider collider;
| + | |
| − | void Start()
| + | |
| − | {
| + | |
| − | animator = GetComponent<Animator>();
| + | |
| − | collider = GetComponent<CapsuleCollider>();
| + | |
| − | }
| + | |
| − | private void OnCollisionEnter(Collision collision)
| + | |
| − | {
| + | |
| − | if (collision.gameObject.tag == "Player")
| + | |
| − | {
| + | |
| − | StartCoroutine(AttackTimer());
| + | |
| − | }
| + | |
| − | }
| + | |
| − | IEnumerator AttackTimer()
| + | |
| − | {
| + | |
| − | animator.SetTrigger("Attack");
| + | |
| − | yield return new WaitForSeconds(1);
| + | |
| − | }
| + | |
| − | }
| + | |
| − | </pre>
| + | |
| − | OnCollisionEnterは衝突時に実行される(オブジェクトが停止すると以降、実行されない)
| + | |