Created
May 7, 2022 03:44
-
-
Save cyberjj999/d9b2403cad2c161db61ccb1d7614cfa7 to your computer and use it in GitHub Desktop.
Becoming A Metaverse Developer Article | Other Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check if player is on the ground | |
public bool IsGrounded() | |
{ | |
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f); | |
} | |
// Runs everytime the player collides with something | |
private void OnCollisionEnter(Collision collision) | |
{ | |
// If player collide with object with 'Win' tag (i.e. Win Zone) | |
if (collision.gameObject.tag == "Win") | |
{ | |
Debug.Log("Win"); | |
// Set WinPanel UI to be Active | |
winPanel.SetActive(true); | |
} | |
// If player collide with object with 'Lose' tag (i.e. Lose Zone) | |
if (collision.gameObject.tag == "Lose") | |
{ | |
RestartGame(); // Restart the game | |
} | |
} | |
// Restart the Game | |
void RestartGame() | |
{ | |
Scene scene = SceneManager.GetActiveScene(); | |
SceneManager.LoadScene(scene.name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment