Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/SpawnDeformation.cs
2026-03-04 09:37:33 +08:00

36 lines
1.4 KiB
C#

using UnityEngine;
public class SpawnDeformation : MonoBehaviour
{
public static float TimeBtwnEachDeformation = 0.5f;
public float thresholdSpeed = 0.75f;
public float maxSpeed = 5f;
public float deformationAmplitudeMultipler = 0.1f;
private float lastDeformationSpawnedTime;
private Vector3 lastPosition = Vector3.zero;
private void Update()
{
Vector3 vector = (base.transform.position - lastPosition) / Time.deltaTime;
float normalizedHeightOfSphereBelowSurface = GetComponent<Buoyancy>().GetNormalizedHeightOfSphereBelowSurface();
if (vector.magnitude > thresholdSpeed && normalizedHeightOfSphereBelowSurface > 0f && normalizedHeightOfSphereBelowSurface < 1f && Time.realtimeSinceStartup - lastDeformationSpawnedTime >= TimeBtwnEachDeformation && PoolManager.Instances[PoolManager.InstanceType.Deformer] != null)
{
GameObject nextAvailable = PoolManager.Instances[PoolManager.InstanceType.Deformer].getNextAvailable();
if (nextAvailable != null)
{
lastDeformationSpawnedTime = Time.realtimeSinceStartup;
nextAvailable.transform.position = base.transform.position + base.transform.forward * vector.magnitude * 0.01f;
float num = Mathf.InverseLerp(thresholdSpeed, maxSpeed, vector.magnitude);
nextAvailable.GetComponent<DeformationManager>().SetAmplitude(num * deformationAmplitudeMultipler);
nextAvailable.SetActive(value: true);
}
}
lastPosition = base.transform.position;
}
}