From 1bdc7226e51adb7560746f54b735e5e7952c3e88 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 27 Oct 2019 02:43:08 +0200 Subject: [PATCH] animate enex --- .../Behaviours/World/EntranceExitMapObject.cs | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Behaviours/World/EntranceExitMapObject.cs b/Assets/Scripts/Behaviours/World/EntranceExitMapObject.cs index 1d49d857..42673a1f 100644 --- a/Assets/Scripts/Behaviours/World/EntranceExitMapObject.cs +++ b/Assets/Scripts/Behaviours/World/EntranceExitMapObject.cs @@ -1,12 +1,20 @@ using UnityEngine; using SanAndreasUnity.Importing.Items.Placements; +using SanAndreasUnity.Utilities; namespace SanAndreasUnity.Behaviours.World { public class EntranceExitMapObject : MapObject { - + Coroutine m_animateArrowCoroutine; + public float minArrowPos = -1f; + public float maxArrowPos = 1f; + public Transform arrowTransform; + public float arrowMoveSpeed = 0.3f; + + + public static EntranceExitMapObject Create(EntranceExit info) { var obj = Object.Instantiate(Cell.Instance.enexPrefab).GetComponent(); @@ -41,6 +49,19 @@ namespace SanAndreasUnity.Behaviours.World } + void OnEnable() + { + m_animateArrowCoroutine = this.StartCoroutine(this.AnimateArrow()); + } + + void OnDisable() + { + if (m_animateArrowCoroutine != null) + this.StopCoroutine(m_animateArrowCoroutine); + m_animateArrowCoroutine = null; + } + + void OnDrawGizmosSelected() { Utilities.F.HandlesDrawText(this.transform.position, this.name, Color.yellow); @@ -78,6 +99,37 @@ namespace SanAndreasUnity.Behaviours.World Debug.LogFormat("OnTriggerEnter() - with {0}", collider.gameObject.name); } + System.Collections.IEnumerator AnimateArrow() + { + + // place arrow at center + float center = (this.minArrowPos + this.maxArrowPos) * 0.5f; + this.arrowTransform.localPosition = this.arrowTransform.localPosition.WithY(center); + + yield return null; + + // move arrow up/down + + // set initial sign (direction of movement) + float sign = Mathf.Sign(Random.Range(-1f, 1f)); + + while (true) + { + float y = this.arrowTransform.localPosition.y; + y += sign * this.arrowMoveSpeed * Time.deltaTime; + if (y >= this.maxArrowPos || y <= this.minArrowPos) + { + // clamp + y = Mathf.Clamp(y, this.minArrowPos, this.maxArrowPos); + // flip direction + sign = - sign; + } + this.arrowTransform.localPosition = this.arrowTransform.localPosition.WithY(y); + yield return null; + } + + } + } }