Skip to content

Instantly share code, notes, and snippets.

@dyguests
Created October 28, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyguests/aac4b562abd0aa1a4cfcdd896423739c to your computer and use it in GitHub Desktop.
Save dyguests/aac4b562abd0aa1a4cfcdd896423739c to your computer and use it in GitHub Desktop.
Unity get self instance in scene.
public static PlayerController FindWithTag()
{
var playerController = GameObject.FindWithTag(Tags.Player).GetComponent<PlayerController>();
if (playerController == null)
{
throw new Exception("playerController not found.");
}
return playerController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment