Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/WorkerBeltApproachingBehaviour.cs

70 lines
2.0 KiB
C#

using Core.SaveLoad;
using UnityEngine;
using Pixelplacement;
using Pixelplacement.TweenSystem;
public class WorkerBeltApproachingBehaviour : AppleState
{
public Spline ApproachingSpline;
public Transform workerObjectTransform;
public float approachduration;
public float approachDelay;
//References to the Worker Gameobject
public GameObject workerBeltObject;
public Animator workerAnimator;
public WorkerBeltRoamingBehaviour workerBeltRoamingRef;
private TweenBase aproachTween;
public AppleMachine workerBeltStateMAchineRef;
private void OnEnable()
{
Transform anchorB = transform.Find("AnchorA");
if (anchorB != null)
{
anchorB.position = workerBeltRoamingRef.midRoamPosition;
}
Debug.Log("Entered Worker Belt Approaching State");
if (ApproachingSpline == null || workerObjectTransform == null)
{
Debug.LogWarning("WorkerBeltApproachingBehaviour: ApproachingSpline or workerObjectTransform is not assigned.", this);
return;
}
// Start the tween to move the worker along the approaching spline
aproachTween = Tween.Spline(
ApproachingSpline,
workerObjectTransform,
0, 1,
false,
approachduration,
approachDelay,
Tween.EaseLinear,
Tween.LoopType.None,
HandleApproachStarted, // optional
HandleApproachFinished // called when spline completes
);
}
private void OnDisable()
{
Debug.Log("Exited Worker Belt Approaching State");
}
// callback implementations
void HandleApproachStarted()
{
// optional: play audio/anim etc.
}
void HandleApproachFinished()
{
Debug.Log("Approach tween finished");
// cleanup
aproachTween?.Stop();
workerAnimator.SetBool("isLifting?", true);
workerBeltStateMAchineRef.ChangeState(2);
}
}