using System; 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(json).FrameInfo; } private void FixedUpdate() { FrameIndex = (FrameIndex + 1) % (Frames.Length - 1); } 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); } } }