Files
Inter-Face-Off/Assets/Scripts/PlayerController.cs
2026-01-15 23:02:24 +00:00

38 lines
1.2 KiB
C#

using System.IO;
using UnityEngine;
namespace InterfaceOff.WorldScene
{
public class PlayerController : MonoBehaviour
{
private static PlayerController Instance;
private PlayerFrameInfo[] Frames;
private int FrameIndex = 0;
private float LerpValue;
private void Awake()
{
string json = File.ReadAllText(Application.dataPath + "/Resources/playerframe.json");
Frames = JsonUtility.FromJson<PlayerFrameInfoArray>(json).FrameInfo;
}
private void FixedUpdate()
{
FrameIndex = (FrameIndex + 1) % (Frames.Length - 2);
}
private void Update()
{
LerpValue = (LerpValue + Time.deltaTime * 20f) % 1f;
PlayerFrameInfo frameA = Frames[FrameIndex + 0];
PlayerFrameInfo frameB = Frames[FrameIndex + 1];
transform.position = Vector3.Lerp(frameA.Position, frameB.Position, LerpValue);
Vector2 rotation = Vector2.Lerp(frameA.Rotation, frameB.Rotation, LerpValue);
transform.rotation = Quaternion.Euler(rotation.x, rotation.y, 0);
}
}
}