mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-15 00:37:09 +00:00
animate enex
This commit is contained in:
parent
47c43384ed
commit
1bdc7226e5
1 changed files with 53 additions and 1 deletions
|
@ -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<EntranceExitMapObject>();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue