- Home /
Question by
dabears · Sep 03, 2014 at 09:48 PM ·
c#achievements
Help implementing Achievements
I have read over the Social API [guide][1]
And attempted an implementation
public class SocialController : MonoBehaviour {
PlayerController playerController = null;
IAchievement scoreAchievement = null;
ILeaderboard leaderboard = null;
public SocialController() {
}
void Start() {
if (playerController == null) {
playerController = GameObject.FindGameObjectWithTag("Player").AddComponent<PlayerController>();
}
// Authenticate and register a ProcessAuthentication callback
// This call needs to be made before we can proceed to other calls in the Social API
Social.localUser.Authenticate(ProcessAuthentication);
leaderboard = Social.CreateLeaderboard();
leaderboard.id = "MainLeaderboard";
leaderboard.LoadScores(result => {
Debug.Log("Received " + leaderboard.scores.Length + " scores");
foreach (IScore score in leaderboard.scores)
Debug.Log(score);
});
IAchievement achievement = Social.CreateAchievement();
achievement.id = "Achievement01";
achievement.percentCompleted = playerController.SCORE;
achievement.ReportProgress(result => {
if (playerController.SCORE > 100)
Debug.Log("Successfully reported progress");
else
Debug.Log("Failed to report progress");
});
}
// This function gets called when Authenticate completes
// Note that if the operation is successful, Social.localUser will contain data from the server.
void ProcessAuthentication(bool success) {
if (success) {
Logger.logSocial("Authenticated, checking achievements");
// Request loaded achievements, and register a callback for processing them
Social.LoadAchievements(ProcessLoadedAchievements);
} else
Logger.logSocial("Failed to authenticate");
}
// This function gets called when the LoadAchievement call completes
void ProcessLoadedAchievements(IAchievement[] achievements) {
if (achievements.Length == 0)
Logger.logSocial("Error: no achievements found");
else
Logger.logSocial("Got " + achievements.Length + " achievements");
// You can also call into the functions like this
Social.ReportProgress("Achievement01", 100.0, result => {
if (result)
Logger.logSocial("Successfully reported achievement progress");
else
Logger.logSocial("Failed to report achievement");
});
}
}
*ignore the Leaderboard, that'll probably be my next question to post
However it seems like Im missing a call to save my custom achievement, or maybe not understanding how to use this API. Because all I get from doing this is an error:
UnityEngine.Debug:Log(Object) TikiBeeGame.SocialController:m__1(Boolean) (at Assets/MyScripts/SocialController.cs:50) UnityEngine.SocialPlatforms.Impl.Achievement:ReportProgress(Action`1) TikiBeeGame.SocialController:Start() (at Assets/MyScripts/SocialController.cs:46) as well as a messageFailed to report progress
UnityEngine.Debug:Log(Object) TikiBeeGame.Logger:logSocial(String) (at Assets/MyScripts/Logger.cs:37) TikiBeeGame.SocialController:ProcessLoadedAchievements(IAchievement[]) (at Assets/MyScripts/SocialController.cs:100) UnityEngine.Social:LoadAchievements(Action`1) TikiBeeGame.SocialController:ProcessAuthentication(Boolean) (at Assets/MyScripts/SocialController.cs:92) UnityEngine.SocialPlatforms.Impl.LocalUser:Authenticate(Action`1) TikiBeeGame.SocialController:Start() (at Assets/MyScripts/SocialController.cs:33) [1]: http://docs.unity3d.com/Manual/net-SocialAPI.htmlError: no achievements found
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Google play achievements problem please help 2 Answers
Achievements Google Play. 1 Answer