48 lines
1008 B
C#
Raw Normal View History

using Mirror;
using QSB.Anglerfish.TransformSync;
using QSB.Utility;
2021-11-09 17:56:45 -08:00
using QSB.WorldSync;
using UnityEngine;
namespace QSB.Anglerfish.WorldObjects
{
public class QSBAngler : WorldObject<AnglerfishController>
{
2022-01-14 22:28:44 -08:00
public AnglerTransformSync TransformSync;
2021-11-10 09:28:05 +00:00
public Transform TargetTransform;
public Vector3 TargetVelocity { get; private set; }
private Vector3 _lastTargetPosition;
2021-11-09 17:56:45 -08:00
public override void Init()
2021-11-09 17:56:45 -08:00
{
if (QSBCore.IsHost)
{
2022-01-14 22:25:23 -08:00
Object.Instantiate(QSBNetworkManager.singleton.AnglerPrefab).SpawnWithServerAuthority();
2021-11-09 17:56:45 -08:00
}
StartDelayedReady();
2021-12-17 19:16:22 -08:00
QSBCore.UnityEvents.RunWhen(() => TransformSync, FinishDelayedReady);
2021-11-09 17:56:45 -08:00
}
public override void OnRemoval()
{
if (QSBCore.IsHost)
{
NetworkServer.Destroy(TransformSync.gameObject);
2021-11-09 17:56:45 -08:00
}
2021-11-09 18:38:19 -08:00
}
public void UpdateTargetVelocity()
2021-11-09 20:35:55 -08:00
{
2021-11-10 09:28:05 +00:00
if (TargetTransform == null)
{
return;
}
2021-11-25 15:38:05 +00:00
2021-11-10 09:28:05 +00:00
TargetVelocity = TargetTransform.position - _lastTargetPosition;
_lastTargetPosition = TargetTransform.position;
2021-11-09 20:35:55 -08:00
}
2021-11-09 17:56:45 -08:00
}
}