- Home /
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.
@Herman Tullekan A better question would be: "Why does QATO doesn't support the tabulator key for code formatting?" Answer:"It's a website where you jump from field to field with the tab key". This means QATO's textfields lack a basic functionality for code formatting, and that makes formatting quite inconvenient. In addition the textfield is not expandable which breaks long code lines thus distorting overview and making formatting even more inconvenient. Formatting should be a no-brainer but is a PIA withs QATO's code formatting feature. As long this is not fixed asking users for correct code formatting is kind of unfair. It's better to ask QATO for better code formatting implementation.
Answer by GuyTidhar · Jul 15, 2011 at 09:37 PM
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;
}
I have not been able to get this to work but I think this is the right answer. I used your code and did not get an error but when I tried to use the same code for another even that only had a different name. I got a group method conversion error or something.
I am sure your answer is right I just need to look into it more to understand it better. Thank you.
Answer by synapsemassage · Jul 15, 2011 at 09:44 PM
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 (http://www.google.com/cse/home?cx=001712401338047450041%3Acsfhqk-trfa) to find answer.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
iOS Game Center Achievements Not Working 1 Answer
Renderer on object disabled after level reload 1 Answer
Did Social.LoadUsers() stop working? 3 Answers