HeavenStudio/Assets/Scripts/Games/Spaceball/Alien.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2021-12-28 07:38:55 +00:00
using UnityEngine;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Games.Scripts_Spaceball
2021-12-28 07:38:55 +00:00
{
public class Alien : MonoBehaviour
{
private Animator anim;
private float showBeat = 0;
private bool isShowing = false;
const string IdleAnim = "AlienIdle";
const string SwingAnim = "AlienSwing";
const string ShowAnim = "AlienShow";
private void Awake()
2021-12-28 07:38:55 +00:00
{
anim = GetComponent<Animator>();
anim.Play(IdleAnim, 0, 0);
2021-12-28 07:38:55 +00:00
}
private void Update()
{
if (Conductor.instance.isPlaying && !isShowing)
2021-12-28 07:38:55 +00:00
{
anim.Play(SwingAnim, 0, Conductor.instance.GetLoopPositionFromBeat(0, 1f));
2021-12-28 07:38:55 +00:00
anim.speed = 0;
}
else if (!Conductor.instance.isPlaying)
2021-12-28 07:38:55 +00:00
{
anim.Play(IdleAnim, 0, 0);
2021-12-28 07:38:55 +00:00
}
if (isShowing)
{
2022-02-03 22:20:26 +00:00
float normalizedBeat = Conductor.instance.GetPositionFromBeat(showBeat, 1f);
anim.Play(ShowAnim, 0, normalizedBeat);
2021-12-28 07:38:55 +00:00
anim.speed = 0;
if (normalizedBeat >= 2)
{
isShowing = false;
}
}
}
public void Show(float showBeat)
{
isShowing = true;
this.showBeat = showBeat;
}
}
}