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

30 lines
747 B
C#
Raw Permalink Normal View History

2021-05-10 22:27:55 +02:00
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;
}
}