check enum from another script?

hey. i have this enum in a script:

public class TeamSelectUi : MonoBehaviour {

	[Header("Player 1")]
	public enum PlayerOneTeam {Red, Blue, None};
	public PlayerOneTeam teamPlayerOne = new PlayerOneTeam();

and i wanna check in another script what the current PlayerOne Team is, like this:

if (TeamSelectUi.PlayerOneTeam == TeamSelectUi.PlayerOneTeam.None) {
				//do something
			}

but i get the error “An object reference is required to access non-static member `TeamSelectUi.teamPlayerOne’” what am i doing wrong?

The property is an Instance property and not static(value shared among the instances, also known as a class variable). So you either need to use GetComponent to get a reference to the TeamSelectUi script or you need to make the variable static so it’s accessiable on the class.

To make it static(which means all instances of TeamSelectUi will share the same property) you would:

public static PlayerOne {Red, Blue, None};

and you could access like you stated in your second code snippet.

Or you need to get the component of whatever game object it’s attached to using GetComponent, but don’t know where the component exists in your implementation.

TeamSelectUi teamselect = someGameObject.GetComponent<TeamSelectUi>();

then get the member like normal.

teamselect.PlayerOneTeam