Made fans move objects

This commit is contained in:
2026-04-11 15:26:19 +01:00
parent 75565f040e
commit 2222294a79
6 changed files with 249 additions and 12 deletions

View File

@@ -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
}
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
using UnityEngine;
using System;
namespace Fruitomation.Game
{
public class TriggerDetector : MonoBehaviour
{
private Action<Collider2D> RegisteredAction;
public void SetAction(Action<Collider2D> action) => RegisteredAction = action;
private void OnTriggerStay2D(Collider2D other) => RegisteredAction?.Invoke(other);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a471a3a004424f44aed18516c22740e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: