Advertisement
kadyr

Untitled

Nov 30th, 2021
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Serialization;
  5.  
  6. namespace Ninsar.Content.Tonnelle.Scripts
  7. {
  8.     public class AudioSyncPosition : AudioSyncer
  9.     {
  10.        
  11.         private IEnumerator MoveToScale(Vector3 _target)
  12.         {
  13.             Vector3 _curr = transform.position;
  14.             Debug.Log(_curr);
  15.             Vector3 _initial = _curr;
  16.             float _timer = 0;
  17.  
  18.             while (_curr != _target)
  19.             {
  20.                 _curr = Vector3.Lerp(_initial, _target, _timer / timeToBeat);
  21.                 _timer += Time.deltaTime;
  22.  
  23.                 transform.position = _curr;
  24.  
  25.                 yield return null;
  26.             }
  27.  
  28.             m_isBeat = false;
  29.         }
  30.  
  31.         public override void OnUpdate()
  32.         {
  33.             base.OnUpdate();
  34.  
  35.             if (m_isBeat) return;
  36.  
  37.             transform.position = Vector3.Lerp(transform.position, restPosition, restSmoothTime * Time.deltaTime);
  38.         }
  39.  
  40.         public override void OnBeat()
  41.         {
  42.             base.OnBeat();
  43.  
  44.             StopCoroutine("MoveToScale");
  45.             StartCoroutine("MoveToScale", beatPosition);
  46.         }
  47.  
  48.         void Start()
  49.         {
  50.             restPosition = transform.position;
  51.             beatPosition = restPosition + new Vector3(0, 0f,0.1f);
  52.         }
  53.  
  54.         public Vector3 beatPosition;
  55.         public Vector3 restPosition;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement