SHADE_Y3/Assets/Scripts/AnimTest.cs

55 lines
1.5 KiB
C#
Raw Normal View History

using System;
namespace SHADE.Test
2023-03-09 15:14:30 +08:00
{
public class AnimTest : Script
{
#region Serialized Fields
[SerializeField]
2023-03-09 15:14:30 +08:00
private AnimationClipAsset fullClip;
[SerializeField]
private AnimationClipAsset idleClip;
[SerializeField]
private AnimationClipAsset runClip;
[SerializeField]
private AnimationClipAsset pickUpClip;
#endregion
#region Components
2023-03-09 15:14:30 +08:00
public Animator Animator { get; private set; }
#endregion
#region Lifecycle Functions
protected override void awake()
{
Animator = GetComponent<Animator>();
}
protected override void update()
{
// Play loop if shift is held
Action<AnimationClipAsset> playFunc = Input.GetKey(Input.KeyCode.LeftShift) ? (x) => Animator.Play(x)
: (x) => Animator.PlayOneShot(x);
// Play animations
2023-03-09 15:14:30 +08:00
if (Input.GetKeyUp(Input.KeyCode.Equals))
{
playFunc(fullClip);
2023-03-09 15:14:30 +08:00
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha1))
{
playFunc(idleClip);
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha2))
{
playFunc(runClip);
}
else if (Input.GetKeyUp(Input.KeyCode.Alpha3))
{
playFunc(pickUpClip);
}
}
#endregion
}
2023-03-09 15:14:30 +08:00
}