I want to display on the screen that the player has achieved their goals in this much time after playing the game. But when I display Time.time it keeps changing. I want to record the time elapsed when the event happens and display it as a fixed number string.
CodePudding user response:
When the player achieves the goal, store Time.time in a class variable (i.e. declared inside the class but outside of any function). Then display that variable rather than Time.time.
CodePudding user response:
Do you want to record the result of the game? If so, you can try to create a new canvas in the scene, and create a new image in the canvas as the background image. You can set the relevant properties of the image through the Inspector interface.
After setting the background, add a Button to the scene, and set the different states of the Button when it is pressed, lifted, and disabled according to personal needs. And add a C# script file under canvas - StartMenuController
The start interface code is:
public void OnStartGameButtonClick()
{
//When the button is pressed, jump to the game interface
SceneManager.LoadScene(1);
//The parameter in the LoadScene() function can be the number of interfaces in builtsettings or the scene name
}
The end interface code is:
public void OnExitButtonClick()
{
Application.Quit();
}
Point each function in the canvas to the onClick of the respective button.Hope it helps you thank you