using System.Collections; using System.Collections.Generic; using UnityEngine; using Mirror; public class SciFiDoor : NetworkBehaviour, IInteractable { [SyncVar] public bool state = false; public float duration = 2f, offset; public AnimationCurve oCurva; public List doorList; private float _posX, _originX; private float _timeElapsed; void Start() { _originX = doorList[0].localPosition.x; } public void Interact() { CmdInteract(); } [Command(requiresAuthority = false)] private void CmdInteract(NetworkConnectionToClient sender = null) { state = !state; } void Update() { _timeElapsed += Time.deltaTime * (state ? 1 : -1); _timeElapsed = Mathf.Clamp(_timeElapsed, 0, duration); float progress = _timeElapsed / duration; _posX = Mathf.Lerp(_originX, _originX + offset, oCurva.Evaluate(progress)); // _posX = Mathf.Lerp(_originX, _originX + offset, Mathf.SmoothStep(0, 1, progress)); for (int i = 1; i <= doorList.Count; i++) { float side = i % 2 == 0 ? -1 : 1; var pos = doorList[i - 1].localPosition; pos.x = _posX * side; doorList[i - 1].localPosition = pos; } } }