HeavenStudioPlus/Assets/Scripts/Games/BlueBear/BlueBear.cs

104 lines
2.8 KiB
C#
Raw Normal View History

2022-03-12 03:15:15 +00:00
using DG.Tweening;
using NaughtyBezierCurves;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Util;
2022-03-12 03:15:15 +00:00
using System;
using System.Collections.Generic;
using UnityEngine;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Games
2022-03-12 03:15:15 +00:00
{
2022-03-12 14:14:41 +00:00
using Scripts_BlueBear;
2022-03-12 03:15:15 +00:00
public class BlueBear : Minigame
{
2022-03-12 14:14:41 +00:00
[Header("Animators")]
public Animator headAndBodyAnim; // Head and body
public Animator bagsAnim; // Both bags sprite
public Animator donutBagAnim; // Individual donut bag
public Animator cakeBagAnim; // Individual cake bag
[Header("References")]
public GameObject donutBase;
public GameObject cakeBase;
public Transform foodHolder;
public GameObject individualBagHolder;
[Header("Curves")]
public BezierCurve3D donutCurve;
public BezierCurve3D cakeCurve;
private bool squashing;
public static BlueBear instance;
private void Awake()
2022-03-12 03:15:15 +00:00
{
2022-03-12 14:14:41 +00:00
instance = this;
}
private void Update()
{
headAndBodyAnim.SetBool("ShouldOpenMouth", foodHolder.childCount != 0);
if (PlayerInput.GetAnyDirectionDown())
{
headAndBodyAnim.Play("BiteL", 0, 0);
}
else if (PlayerInput.Pressed())
{
headAndBodyAnim.Play("BiteR", 0, 0);
}
}
private void LateUpdate()
{
if (squashing)
{
var dState = donutBagAnim.GetCurrentAnimatorStateInfo(0);
var cState = cakeBagAnim.GetCurrentAnimatorStateInfo(0);
bool noDonutSquash = dState.IsName("DonutIdle");
bool noCakeSquash = cState.IsName("CakeIdle");
if (noDonutSquash && noCakeSquash)
{
squashing = false;
bagsAnim.Play("Idle", 0, 0);
}
}
2022-03-12 03:15:15 +00:00
}
2022-03-12 14:14:41 +00:00
public void SpawnTreat(float beat, bool isCake)
2022-03-12 03:15:15 +00:00
{
2022-03-12 14:14:41 +00:00
var objectToSpawn = isCake ? cakeBase : donutBase;
var newTreat = GameObject.Instantiate(objectToSpawn, foodHolder);
2022-03-12 03:15:15 +00:00
2022-03-12 14:14:41 +00:00
var treatComp = newTreat.GetComponent<Treat>();
treatComp.startBeat = beat;
treatComp.curve = isCake ? cakeCurve : donutCurve;
newTreat.SetActive(true);
Jukebox.PlayOneShotGame(isCake ? "blueBear/cake" : "blueBear/donut");
SquashBag(isCake);
}
public void SquashBag(bool isCake)
{
squashing = true;
bagsAnim.Play("Squashing", 0, 0);
individualBagHolder.SetActive(true);
if (isCake)
{
cakeBagAnim.Play("CakeSquash", 0, 0);
}
else
{
donutBagAnim.Play("DonutSquash", 0, 0);
}
2022-03-12 03:15:15 +00:00
}
}
}