48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Fruitomation.Game.Items;
|
|
using Fruitomation.Global;
|
|
using UnityEngine;
|
|
|
|
namespace Fruitomation.Game
|
|
{
|
|
public class FanBuilding : Building
|
|
{
|
|
[Header("Fan Specific Items")]
|
|
[SerializeField] private TriggerDetector TriggerDetector;
|
|
|
|
[SerializeField] private Animator FanAnimator;
|
|
|
|
private void Start()
|
|
{
|
|
TriggerDetector.SetAction(other =>
|
|
{
|
|
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
|
|
{
|
|
Vector3 force = new(-transform.localScale.x, 0f, 0f);
|
|
body?.AddForce(force * Mathf.PI, ForceMode2D.Impulse);
|
|
}
|
|
}, TriggerType.Stay);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (GameStateController.Is(GameState.Simulation))
|
|
{
|
|
if (FanAnimator.speed == 0)
|
|
{
|
|
FanAnimator.Play(0, 0, 0f); // Play from beginning
|
|
FanAnimator.speed = 1; // Playing
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if (FanAnimator.speed != 0)
|
|
{
|
|
FanAnimator.Play(0, 0, 0f); // Jump back to default frame
|
|
FanAnimator.speed = 0; // Paused
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|