Prime 31 Game Center - C# question

Hi Unity Community, or should I say… Hi Eric…

So I downloaded Prime 31’s Game Center plugin. It would great but the hole thing is in C# and I learned JavaScript or as We would say “Unity Script” from tutorials to create games.

Game Center Manager file has an event that is fired when someone logs in

// Fired when a player is logged in

public static event GameCenterEventHandler playerAuthenticated;

Problem I have is that I dont really know what an event is. I would like for it to trigger… lets say a Debug.Log. But it does not work like a function

public static event GamecenterEventHandler playerAuthenticated(){
    Debug.Log("player logged in");
}

What I am trying to do is use this to check if the person logged in or not and make the appropriate buttons available by turning booleans off and on.

You need to be registered to an event in order to respond to it.

For that you define a function of the type of the event and register it.

You need to know if GameCenterEventHandler takes arguments or not and according to that you can define your handlers.

For instance:
If GameCenterEventHandler takes no arguments and function without arguments can be registered to handle it:

public static void OnPlayerAuthenticated()
{
   Debug.Log("player logged in");
}

And you register like this:

void Start()
{
   playerAuthenticated += OnPlayerAuthenticated;
}

function Awake ()
{
GameCenterManager.playerAuthenticated += myPlayerIsAuthenticatedMethod;
}

“myPlayerIsAuthenticatedMethod” is your function ( e.g. your button functionality) going to be executed when event occurs.
You should also kill the eventlistener when loading new scene or then you don’t need it anymore. For example:

 function OnDisable ()
    {
    GameCenterManager.playerAuthenticated -= myPlayerIsAuthenticatedMethod;
    }

Checkout out the examples coming with the plugin, although Prime31 examples are C# you will find usefull info how to use it also the forum thread is quiote useful. Use this Unitysearch (Programmable Search Engine) to find answer.