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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
Assets/Scripts/Game/TriggerDetector.cs
Normal file
13
Assets/Scripts/Game/TriggerDetector.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Game/TriggerDetector.cs.meta
Normal file
11
Assets/Scripts/Game/TriggerDetector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a471a3a004424f44aed18516c22740e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user