Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/WorkerBeltApproachingBehaviour.cs
2025-12-04 14:38:32 +01:00

78 lines
2.2 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);
}
public void Update()
{
if (ApproachingSpline.GetDirection(aproachTween.Percentage).x > 0.1)
workerAnimator.SetBool("walkingRight?", true);
else
workerAnimator.SetBool("walkingRight?", false);
}
}