using System; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.UI; public class WindController : MonoBehaviour, ITask { [Header("Settings větru")] public float maxWindTorque = 8f; public float windChangeSpeed = 0.6f; public float gustInterval = 4f; public float gustMultiplier = 2.0f; public float CurrentWindTorque { get; private set; } private float targetTorque; private float gustTimer; private Action _onCompleted; private Action _onExit; public string TaskID { get; set; } public TaskType TaskType { get; set; } public string TaskName { get; set; } public (double, double) TaskLocation { get; set; } public bool IsCompleted { get; private set; } void Start() { PickNewTargetTorque(); gustTimer = gustInterval; } void Update() { CurrentWindTorque = Mathf.Lerp(CurrentWindTorque, targetTorque, Time.deltaTime * windChangeSpeed); gustTimer -= Time.deltaTime; if (gustTimer <= 0f) { float gust = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque) * gustMultiplier; targetTorque = Mathf.Clamp(gust, -maxWindTorque * gustMultiplier, maxWindTorque * gustMultiplier); gustTimer = gustInterval; Invoke(nameof(PickNewTargetTorque), 0.8f); } } private void PickNewTargetTorque() { targetTorque = UnityEngine.Random.Range(-maxWindTorque, maxWindTorque); } public void Initialize(Action onCompleted) { _onCompleted = onCompleted; IsCompleted = false; } public void Complete() { if (IsCompleted) return; IsCompleted = true; _onCompleted?.Invoke(this); } public void ExitTask(Action onExit) { _onExit = onExit; _onExit?.Invoke(this); } }