sea-battle/Assets/Scripts/UI/SineText.cs

102 lines
2.4 KiB
C#

using TMPro;
using UnityEngine;
public class SineText : MonoBehaviour
{
[SerializeField] private TMP_Text guide;
[SerializeField] private float amplitude = 5f; // íŕńęîëüęî óâĺëč÷čâŕĺňń˙/óěĺíüřŕĺňń˙ đŕçěĺđ
[SerializeField] private float speed = 2f; // ńęîđîńňü ďóëüńŕöčč
private float baseSize;
private int playerId = 1;
private bool playerReady;
private bool enemyReady;
private void OnEnable()
{
GameManager.OnReady += ChangText;
}
private void OnDisable()
{
GameManager.OnReady -= ChangText;
guide.text = "Đŕńńňŕâü ęîđŕáëč !";
guide.color = new Color(0, 194, 255);
}
void Start()
{
if (guide != null)
baseSize = guide.fontSize; // ńîőđŕí˙ĺě čńőîäíűé đŕçěĺđ řđčôňŕ
var player = GetComponentInParent<Player>();
if (player != null) playerId = player.PlayerId;
}
public void ChangText(int playerId, bool ready, GameMode gameMode)
{
if (gameMode == GameMode.PlayerVsBot)
{
if (this.playerId == playerId)
{
playerReady = ready;
if (playerReady)
{
guide.text = "Ćěč â ÁÎÉ!!!";
guide.color = new Color32(52, 255, 7, 255);
}
else
{
guide.text = "Đŕńńňŕâü ęîđŕáëč !";
guide.color = new Color(0, 194, 255);
}
}
}
else
{
if(this.playerId == playerId)
{
playerReady = ready;
}
else
{
enemyReady = ready;
}
if (playerReady && enemyReady)
{
guide.text = "Ćěč â ÁÎÉ!!!";
guide.color = Color.red;
}
else if (playerReady && !enemyReady)
{
guide.text = "Ćäĺě ďđîňčâíčęŕ...";
guide.color = Color.green;
}
else
{
guide.text = "Đŕńńňŕâü ęîđŕáëč !";
guide.color = new Color(0, 194, 255);
}
}
}
void Update()
{
if (guide == null) return;
// ńîçäŕ¸ě ńčíóńîčäŕëüíóţ ďóëüńŕöčţ
float newSize = baseSize + Mathf.Sin(Time.time * speed) * amplitude;
guide.fontSize = newSize;
}
}