using System; using Obvious.Soap; using UnityEngine; public class SonarViewObject : MonoBehaviour { public bool Enabled; public FloatVariable SonarRefreshRate; public FloatVariable SonarDepthSetting; public float Depth; private RectTransform _RectTransform; public Vector2 MinMaxDepth; public float DestroyXPos = -0.25f; private Vector3 _startPosition; public event Action OnReachOutScreen; private void Awake() { _RectTransform = GetComponent(); _startPosition = _RectTransform.anchoredPosition; } public void ResetObject() { Enabled = false; _RectTransform.anchoredPosition = _startPosition; this.OnReachOutScreen = null; } private void Update() { if (Enabled) { _RectTransform.anchoredPosition -= new Vector2(1f, 0f) * SonarRefreshRate.Value * Time.deltaTime; float y = Mathf.Lerp(MinMaxDepth.y, MinMaxDepth.x, Depth / SonarDepthSetting.Value); _RectTransform.anchoredPosition = new Vector2(_RectTransform.anchoredPosition.x, y); if (_RectTransform.anchoredPosition.x < DestroyXPos) { this.OnReachOutScreen?.Invoke(this); } } } }