cast GameObject to other type.

I’m trying this:

public player playerVar;
void Start () {
		playerVar = (player)GameObject.Find("player");

And I receive the follow error: error CS0030: Cannot convert type `UnityEngine.GameObject’ to ‘player’

What can I do this cast?
I searched on google an solution but i didn’t found any thing.


I can’t tell how “player” is defined from your snip. But…

If “player” is a class you’ve derived from MonoBehavior for an object component, which you’ve applied to a GameObject instance also named “player”, then you’ll need to do:

GameObject playerGameObj = GameObject.Find("player");
if (playerGameObj != null)
   playerVar = playerGameObj.GetComponent<player>();