Engine-Pong/Game/Behaviours/PongTextBehaviour.cs

28 lines
662 B
C#
Raw Normal View History

2024-01-30 12:43:30 +03:00
using Syntriax.Engine.Core;
namespace Pong.Behaviours;
public class PongTextBehaviour(bool IsLeft) : TextBehaviour
{
public bool IsLeft { get; } = IsLeft;
private PongManager? pongManager = null;
protected override void OnFirstActiveFrame()
{
if (!GameObject.GameManager.TryFindBehaviour(out pongManager))
return;
pongManager.OnScored += UpdateScores;
pongManager.OnReset += UpdateScores;
}
private void UpdateScores(PongManager pongManager)
{
if (IsLeft)
Text = pongManager.ScoreLeft.ToString();
else
Text = pongManager.ScoreRight.ToString();
}
}