HeavenStudioPlus/Assets/Scripts/Games/RhythmTweezers/Tweezers.cs

92 lines
2.6 KiB
C#
Raw Normal View History

2022-02-09 03:58:25 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
2022-02-09 03:58:25 +00:00
using RhythmHeavenMania.Util;
namespace RhythmHeavenMania.Games.RhythmTweezers
{
public class Tweezers : MonoBehaviour
{
public int hitOnFrame;
[NonSerialized] public Animator anim;
2022-02-09 06:52:50 +00:00
private Animator vegetableAnim;
2022-02-10 08:13:54 +00:00
private RhythmTweezers game;
private bool plucking;
2022-02-09 03:58:25 +00:00
private void Start()
{
anim = GetComponent<Animator>();
2022-02-09 06:52:50 +00:00
vegetableAnim = RhythmTweezers.instance.VegetableAnimator;
2022-02-10 08:13:54 +00:00
game = RhythmTweezers.instance;
2022-02-09 03:58:25 +00:00
}
private void LateUpdate()
{
if (PlayerInput.Pressed())
{
if (!plucking) // Did you do a successful pluck earlier in the frame?
{
anim.Play("Tweezers_Pluck", 0, 0);
}
2022-02-09 03:58:25 +00:00
}
plucking = false;
2022-02-09 03:58:25 +00:00
}
public void Pluck(bool ace, Hair hair)
{
if (ace)
{
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
hair.hairSprite.SetActive(false);
hair.stubbleSprite.SetActive(true);
game.hairsLeft--;
if (game.hairsLeft <= 0)
vegetableAnim.Play("HopFinal", 0, 0);
else
vegetableAnim.Play("Hop", 0, 0);
anim.Play("Tweezers_Pluck_Success", 0, 0);
2022-02-09 03:58:25 +00:00
}
else
{
Jukebox.PlayOneShotGame($"rhythmTweezers/shortPluck{UnityEngine.Random.Range(1, 21)}");
Jukebox.PlayOneShot("miss");
hair.hairSprite.SetActive(false);
hair.missedSprite.SetActive(true);
vegetableAnim.Play("Blink", 0, 0);
anim.Play("Tweezers_Pluck_Fail", 0, 0);
}
plucking = true; // Prevents standard pluck from playing in LateUpdate().
2022-02-09 03:58:25 +00:00
}
2022-02-10 08:13:54 +00:00
public void LongPluck(bool ace, LongHair hair)
{
anim.Play("Tweezers_Pluck", 0, 0);
if (hitOnFrame > 0) return;
if (ace)
{
float beat = Conductor.instance.songPositionInBeats;
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound($"rhythmTweezers/longPull{UnityEngine.Random.Range(1, 5)}", beat),
2022-02-10 08:13:54 +00:00
new MultiSound.Sound("rhythmTweezers/longPullEnd", beat + 0.5f),
});
Destroy(hair.gameObject);
}
}
2022-02-09 03:58:25 +00:00
}
}