Finish my animations

This commit is contained in:
BuyMyMojo 2023-02-26 02:09:56 +11:00
parent 7c0c6eda6a
commit 0859e4b36c
12 changed files with 156 additions and 23 deletions

View file

@ -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;
}
}

View 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());
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2604af0af2915a4449b6d902e37340ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: