Finish my animations
This commit is contained in:
parent
7c0c6eda6a
commit
0859e4b36c
12 changed files with 156 additions and 23 deletions
|
@ -7,6 +7,8 @@ public class Player : MonoBehaviour
|
|||
|
||||
[SerializeField] private float moveSpeed = 7f;
|
||||
|
||||
private bool isWalking;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector2 inputVector = new Vector2(0,0);
|
||||
|
@ -33,9 +35,15 @@ public class Player : MonoBehaviour
|
|||
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
|
||||
transform.position += moveDir * moveSpeed * Time.deltaTime;
|
||||
|
||||
float rotateSpeed = 10f;
|
||||
isWalking = moveDir != Vector3.zero;
|
||||
|
||||
float rotateSpeed = 10f;
|
||||
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
||||
}
|
||||
|
||||
public bool IsWalking()
|
||||
{
|
||||
return isWalking;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
23
Assets/Scripts/PlayerAnimator.cs
Normal file
23
Assets/Scripts/PlayerAnimator.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimator : MonoBehaviour
|
||||
{
|
||||
|
||||
private const string IS_WALKING = "IsWalking";
|
||||
|
||||
[SerializeField] private Player player;
|
||||
private Animator animator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
animator.SetBool(IS_WALKING, player.IsWalking());
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/PlayerAnimator.cs.meta
Normal file
11
Assets/Scripts/PlayerAnimator.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2604af0af2915a4449b6d902e37340ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue