28 lines
662 B
C#
28 lines
662 B
C#
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();
|
|
}
|
|
}
|