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

90 lines
2.4 KiB
C#
Raw Normal View History

using Core.SaveLoad;
using UnityEngine;
using Pixelplacement;
using Pixelplacement.TweenSystem;
2025-12-04 14:38:32 +01:00
using System.Collections;
public class WorkerBeltRoamingBehaviour : AppleState
{
public Spline RoamingSpline;
public Transform workerObjectTransform;
public float roamDuration;
public float roamDelay;
2025-12-04 14:38:32 +01:00
public bool walkingRight;
public bool pantsLess;
public Coroutine pantsRoutine;
//References to the Worker Gameobject
public GameObject workerBeltObject;
public Animator workerAnimator;
public Vector3 midRoamPosition;
// Reference to the active spline tween so we can pause/stop it
private TweenBase roamingTween;
void OnEnable()
{
workerAnimator.SetBool("isLifting?", false);
Debug.Log("Entered Worker Belt Roaming State");
if (RoamingSpline == null || workerObjectTransform == null)
{
Debug.LogWarning("WorkerBeltRoamingBehaviour: RoamingSpline or workerObjectTransform is not assigned.", this);
return;
}
// Store the returned TweenBase so we can control it later
roamingTween = Tween.Spline(RoamingSpline, workerObjectTransform, 0, 1, false, roamDuration, roamDelay, Tween.EaseLinear, Tween.LoopType.Loop);
2025-12-04 14:38:32 +01:00
if (pantsLess)
{
pantsRoutine = StartCoroutine(RandomFallChance());
}
}
// Also stop the tween if the GameObject is disabled for any reason (covers StateMachine deactivation)
void OnDisable()
{
midRoamPosition = workerObjectTransform.position;
Debug.Log("WorkerBeltRoamingBehaviour: OnExitState - stopping roaming tween" + midRoamPosition);
roamingTween?.Stop();
}
2025-12-04 14:38:32 +01:00
public void Update()
{
if (RoamingSpline.GetDirection(roamingTween.Percentage).x > 0.1)
workerAnimator.SetBool("walkingRight?", true);
else
workerAnimator.SetBool("walkingRight?", false);
}
IEnumerator RandomFallChance()
{
while (pantsLess)
yield return new WaitForSeconds(2);
CheckForFall();
}
public void CheckForFall()
{
int _randNumber;
_randNumber = Random.Range(0, 1);
if (_randNumber > 5)
{
workerAnimator.SetTrigger("shouldFall?");
}
}
public void OnDestroy()
{
if (pantsRoutine != null)
{
StopCoroutine(pantsRoutine);
}
}
}