Skip to content

Instantly share code, notes, and snippets.

@cyberjj999
Created May 7, 2022 03:44
Show Gist options
  • Save cyberjj999/d9b2403cad2c161db61ccb1d7614cfa7 to your computer and use it in GitHub Desktop.
Save cyberjj999/d9b2403cad2c161db61ccb1d7614cfa7 to your computer and use it in GitHub Desktop.
Becoming A Metaverse Developer Article | Other Methods
// 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