78 lines
1.6 KiB
C#
78 lines
1.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class MissileAlertScript : MonoBehaviour
|
|||
|
{
|
|||
|
#region PROPERTIES
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
#region VARIABLES
|
|||
|
private float blinkInterval = 0.2f;
|
|||
|
private bool isBlinking = false;
|
|||
|
private SpriteRenderer spriteRenderer;
|
|||
|
|
|||
|
private Vector3 position;
|
|||
|
|
|||
|
#endregion
|
|||
|
#region EVENTS
|
|||
|
#endregion
|
|||
|
#region METHODS
|
|||
|
|
|||
|
private IEnumerator Blink()
|
|||
|
{
|
|||
|
isBlinking = true;
|
|||
|
while (isBlinking)
|
|||
|
{
|
|||
|
SetSpriteVisible(true);
|
|||
|
yield return new WaitForSeconds(blinkInterval);
|
|||
|
SetSpriteVisible(false);
|
|||
|
yield return new WaitForSeconds(blinkInterval);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetSpriteVisible(bool isVisible)
|
|||
|
{
|
|||
|
spriteRenderer.enabled = isVisible;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
#region LIFECYCLE
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
position = transform.position;
|
|||
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
|||
|
|
|||
|
var mainCamera = Camera.main;
|
|||
|
position.x = mainCamera.transform.position.x + mainCamera.orthographicSize * mainCamera.aspect - 1f;
|
|||
|
transform.position = position;
|
|||
|
|
|||
|
SetSpriteVisible(false);
|
|||
|
enabled = false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
if (!isBlinking)
|
|||
|
{
|
|||
|
StartCoroutine(Blink());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
if (isBlinking)
|
|||
|
{
|
|||
|
StopCoroutine(Blink());
|
|||
|
SetSpriteVisible(false); // Assure que le sprite est invisible quand on arr<72>te le clignotement
|
|||
|
isBlinking = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|