A UI title screen Razor component that displays a single div with a configurable string and listens for the Space key. When Space is pressed it resets ScoreManager.CurrentScore to 0 and loads the configured SceneFile.
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root>
<div class="title">@MyStringValue</div>
</root>
@code
{
[Property] public SceneFile nextscene { get; set; }
[Property, TextArea] public string MyStringValue { get; set; } = "Press Space Key";
protected override void OnUpdate()
{
if (Input.Keyboard.Pressed("Space"))
{
ScoreManager.CurrentScore = 0;
Scene.Load(nextscene);
}
}
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine( MyStringValue );
}