using OctoCore.Components; using UnityEngine; public class SandController : MonoBehaviour { [System.Serializable] public class References { public Renderer SandRenderer; public Transform[] GlitchBlocksLeft; public Transform[] GlitchBlocksRight; public Transform[] GlitchBlocksTop; } [System.Serializable] public class Settings { public float Duration = 25; public float Delay = 2; } [SerializeField] private References _references; [SerializeField] private Settings _settings; private float _time; private Vector3[] _movesMultiplier = new Vector3[3] { Vector3.left, Vector3.right, Vector3.up }; private Vector3[] _movesOffset = new Vector3[3] { new Vector3(-2.02f, 1.5f, 0), new Vector3(2.02f, 1.5f, 0), new Vector3(0, 3.52f, 0) }; void Start() { _time = -_settings.Delay; for (int i = 0; i < _references.GlitchBlocksLeft.Length; i++) SetBlocScale(_references.GlitchBlocksLeft[i], 0); for (int i = 0; i < _references.GlitchBlocksRight.Length; i++) SetBlocScale(_references.GlitchBlocksRight[i], 1); for (int i = 0; i < _references.GlitchBlocksTop.Length; i++) SetBlocScale(_references.GlitchBlocksTop[i], 2); } void Update() { _time += Time.deltaTime; float progression = Mathf.Clamp01(_time / _settings.Duration); _references.SandRenderer.material.SetFloat("_Progression", progression); if (!OctoPlayer.Instance) return; Vector3 targetPos = _references.SandRenderer.transform.position; targetPos.z = OctoPlayer.Instance.transform.position.z; _references.SandRenderer.transform.position = targetPos; //SandRenderer.transform.rotation = OctoPlayer.Instance.transform.rotation; for (int i = 0; i < _references.GlitchBlocksLeft.Length; i++) SetBlocPosition(_references.GlitchBlocksLeft[i], 0); for (int i = 0; i < _references.GlitchBlocksRight.Length; i++) SetBlocPosition(_references.GlitchBlocksRight[i], 1); for (int i = 0; i < _references.GlitchBlocksTop.Length; i++) SetBlocPosition(_references.GlitchBlocksTop[i], 2); } void SetBlocScale(Transform tr, int i) { tr.localScale = new Vector3(tr.localScale.x, tr.localScale.y, Mathf.Lerp(2, 4, i * 37.05f % 1)); } void SetBlocPosition(Transform tr, int i) { Vector3 moveOffset = _movesOffset[i]; Vector3 moveMultiplier = _movesMultiplier[i]; float id = tr.GetSiblingIndex() + i * 9.12f; float offset = _time * Mathf.Lerp(1, 1.3f, _time); offset *= Mathf.Lerp(3, 8, id * 6.23f % 1); offset += id * 17.23f; offset = Mathf.Cos(offset); offset = Mathf.Clamp01(offset * 6 - 2); //float amplitude = Time.timeSinceLevelLoad * Mathf.Lerp(.03f, .02f, id * 6.23f % 1); float amplitude = id * 23.18f % 1; amplitude *= Mathf.Clamp01(_time); amplitude *= 1 + _time * .05f; amplitude *= .3f; amplitude = Mathf.Clamp01(amplitude); Vector3 targetPos = moveOffset - moveMultiplier * offset * amplitude; targetPos.z = tr.localPosition.z; tr.localPosition = targetPos; } }