Made fans move objects
This commit is contained in:
@@ -1,7 +1,45 @@
|
||||
namespace Fruitomation.Game
|
||||
using Fruitomation.Global;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Fruitomation.Game
|
||||
{
|
||||
public class FanBuilding : BuildingBase
|
||||
{
|
||||
|
||||
[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))
|
||||
{
|
||||
body?.AddForce(-transform.right * Mathf.PI, ForceMode2D.Impulse);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user