revival/game/Assets/Scripts/Animation/Oscillate.cs

30 lines
747 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Ktyl.Util;
using UnityEngine;
public class Oscillate : MonoBehaviour
{
[SerializeField] private float _amplitude = 1;
[SerializeField] private float _period = 1;
[SerializeField] private SerialFloat _objectTimeScale;
private Vector3 _initialPosition;
private float _time;
private void OnEnable()
{
_initialPosition = transform.localPosition;
}
private void LateUpdate()
{
_time += Time.deltaTime * _objectTimeScale;
var oscillate = Mathf.Sin(_time / _period) * _amplitude;
transform.localPosition = _initialPosition + transform.up * oscillate;
}
}