Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/UnityStandardAssets/Utility/SmoothFollow.cs
2026-03-04 10:03:45 +08:00

82 lines
1.9 KiB
C#

using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Utility
{
public class SmoothFollow : MonoBehaviour
{
public enum ViewMode
{
ThirdPerson = 0,
FishView = 1
}
public Transform target;
public float distance = 10f;
[SerializeField]
private float mouseYSensitive = 2f;
[SerializeField]
private float mouseXSensitive = 2f;
private float height = 5f;
private float verticalInput;
private float horizontalInput;
[SerializeField]
private float rotationDamping;
[SerializeField]
private float heightDamping;
public ViewMode viewMode;
private void Start()
{
}
private void LateUpdate()
{
if ((bool)target)
{
ViewMode viewMode = this.viewMode;
if (viewMode != ViewMode.ThirdPerson && viewMode == ViewMode.FishView)
{
FishViewMode();
}
}
}
private void FishViewMode()
{
verticalInput += CrossPlatformInputManager.GetAxis("Mouse Y") * Time.deltaTime * 1f;
horizontalInput += CrossPlatformInputManager.GetAxis("Mouse X") * Time.deltaTime * 50f;
verticalInput = Mathf.Clamp(verticalInput, 0.3f, 2f);
horizontalInput = Mathf.Clamp(horizontalInput, -45f, 45f);
float b = target.eulerAngles.y + horizontalInput;
height = 0f;
float b2 = target.position.y + height;
float y = base.transform.eulerAngles.y;
float y2 = base.transform.position.y;
y = Mathf.LerpAngle(y, b, rotationDamping * Time.deltaTime);
y2 = Mathf.Lerp(y2, b2, heightDamping * Time.deltaTime);
Quaternion quaternion = Quaternion.Euler(0f, y, 0f);
base.transform.position = target.position;
base.transform.position -= quaternion * Vector3.forward * verticalInput;
base.transform.position = new Vector3(base.transform.position.x, y2, base.transform.position.z);
base.transform.LookAt(target);
}
private void OnEnable()
{
verticalInput = 0f;
horizontalInput = 0f;
base.transform.LookAt(target);
}
}
}