void RestartGame() {
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
void PauseGame () {
Time.timeScale = 0;
// ShowPauseMenu();
// also stop accepting input, to move the player etc
// you can do this by setting a global static variable
// -- how? see "Data between scenes" section of this doc
}
void ResumeGame () {
Time.timeScale = 1;
// HidePauseMenu();
// allow user input
}
void PositionAtCursor(Transform transform) {
var screenPoint = Input.mousePosition;
// TODO: use rectTransform component
transform.position = screenPoint;
// works on any object using a rect transform
}
Button click - Call any method with any arguments
- Move to point on ground script
- Click To Move in Unity 5 - 5 mins
- What about walking around obstacles? Use a Nav Mesh
- Like Binding of Isaac, smooth and quick stopping, but 2x speed when moving diagonal
- Same script as above with normalized speed
Three major ways:
- Save info into file using Unity's
PlayerPrefs
- Static class data
- DontDestroyOnLoad with a Singleton object
Example code from tutorial: https://gist.github.com/troy-lamerton/f895b856d2972e9b9f1bb69133a32574
Implemented GlobalState class: https://gist.github.com/troy-lamerton/6701c62763fb29723a750f78bab22163
Youtube source: https://www.youtube.com/watch?v=WchH-JCwVI8 (1hr 10min)