27 lines
917 B
C#
27 lines
917 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace InterfaceOff.WorldScene
|
|
{
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
private static PlayerController Instance;
|
|
|
|
[field: SerializeField] private float PlayerSpeed { get; set; }
|
|
[field: SerializeField] private Transform[] LerpPositions;
|
|
private float LerpValue;
|
|
|
|
private void Update()
|
|
{
|
|
int section = Mathf.FloorToInt(LerpValue);
|
|
Vector3 a = LerpPositions[section + 0].position;
|
|
Vector3 b = LerpPositions[section + 1].position;
|
|
|
|
LerpValue += PlayerSpeed / Vector3.Distance(a, b) * Time.deltaTime;
|
|
LerpValue %= LerpPositions.Length - 1; // Makes lerp value wrap around
|
|
|
|
float sectionLerp = Math.Clamp(LerpValue, section, section + 1) - section;
|
|
transform.position = Vector3.Lerp(a, b, sectionLerp);
|
|
}
|
|
}
|
|
} |