51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using BehaviorDesigner.Runtime.Tasks;
|
|
using UnityEngine;
|
|
|
|
internal class FishHoverNearTarget : FishMove
|
|
{
|
|
private float distanceToTarget = 0.5f;
|
|
|
|
private float hoverTime = 20f;
|
|
|
|
private float timer = -1f;
|
|
|
|
private Vector3 destination;
|
|
|
|
private float maxDistanceDelta = 0.03f;
|
|
|
|
[HideInInspector]
|
|
public new Transform transform;
|
|
|
|
public override void OnStart()
|
|
{
|
|
transform = GetComponent<Transform>();
|
|
base.OnStart();
|
|
timer = Time.time;
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (Time.timeScale == 0f)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
Vector3 vector = Target();
|
|
float num = vector.y;
|
|
if (vector.y > 0f - fish.fishHalfHeight)
|
|
{
|
|
num -= fish.fishHalfHeight;
|
|
}
|
|
else if (vector.y < fish.terrainLevel.y + fish.fishHalfHeight)
|
|
{
|
|
num += fish.fishHalfHeight;
|
|
}
|
|
transform.position = Vector3.MoveTowards(transform.position, new Vector3(vector.x, num, vector.z), maxDistanceDelta);
|
|
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(fish.pullDirection), turnRate.Value);
|
|
if (timer < Time.time)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
return TaskStatus.Running;
|
|
}
|
|
}
|