r2mods/ilspy_dump/ror2_csproj/ProjectileGhostTriggerOnSti...

51 lines
1.2 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using UnityEngine;
using UnityEngine.Events;
public class ProjectileGhostTriggerOnStick : MonoBehaviour
{
private Vector3 lastPosition;
private Quaternion lastRotation;
private bool begunMoving;
private bool finishedMoving;
[SerializeField]
[Tooltip("If the object is rotating, will we consider that movement?")]
private bool trackRotationAsMovement;
[SerializeField]
private UnityEvent OnStick;
private void OnEnable()
{
begunMoving = false;
finishedMoving = false;
lastPosition = base.transform.position;
lastRotation = base.transform.rotation;
}
private void Update()
{
Vector3 position = base.transform.position;
Quaternion rotation = base.transform.rotation;
if (!begunMoving && position != lastPosition && (!trackRotationAsMovement || (trackRotationAsMovement && rotation != lastRotation)))
{
begunMoving = true;
}
else if (begunMoving && !finishedMoving && position == lastPosition && (!trackRotationAsMovement || (trackRotationAsMovement && rotation == lastRotation)))
{
RunStuckMethod();
finishedMoving = true;
}
lastPosition = position;
lastRotation = rotation;
}
public void RunStuckMethod()
{
OnStick.Invoke();
}
}