Hello everyone, I ran into such a problem.
When viewing ads, it is rewarded in different ways (two or four), although I put one each.
the translation may be incorrect (translator)
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using PlayFab; using PlayFab.ClientModels; using Newtonsoft.Json; public class ScoreManager : MonoBehaviour { public TextMeshProUGUI scoreText, tokenText, bonusScoreText, bonusScoreText2; private Animation scoreTextAnim, tokenTextAnim, bonusScoreTextAnim, bonusScoreTextAnim2; [HideInInspector] public int score = 0; private string[] bonusTexts = new string[] { "Amazing", "Nice shot", "Rampage", "Great one", "Fantastic", "Unbelievable", "Great", "Nice", "Impressive" }; public string PlayFabId; //это логин :) void Login(string titleId) { LoginWithCustomIDRequest request = new LoginWithCustomIDRequest () { TitleId = titleId, CreateAccount = true, CustomId = SystemInfo.deviceUniqueIdentifier }; PlayFabClientAPI.LoginWithCustomID (request, (result) => { PlayFabId = result.PlayFabId; Debug.Log ("Got PlayFabID: " + PlayFabId); if (result.NewlyCreated) { Debug.Log ("(new account)"); } else { Debug.Log ("(existing account)"); GetVirtualCurrentcies(); } }, (error) => { Debug.Log ("Error logging in player with custom ID:"); }); } void AndroidLogin(string titleId) { LoginWithAndroidDeviceIDRequest request = new LoginWithAndroidDeviceIDRequest () { TitleId = titleId, CreateAccount = true, AndroidDeviceId = SystemInfo.deviceUniqueIdentifier }; PlayFabClientAPI.LoginWithAndroidDeviceID (request, (result) => { PlayFabId = result.PlayFabId; Debug.Log ("Got PlayFabID: " + PlayFabId); if (result.NewlyCreated) { Debug.Log ("(new account)"); } else { Debug.Log ("(existing account)"); GetVirtualCurrentcies(); } }, (error) => { Debug.Log ("Error logging in player with custom ID:"); }); } // тут логин закончился void GetVirtualCurrentcies() { PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), GetLol, OnError); } void GetLol(GetUserInventoryResult result) { tokenText.text = result.VirtualCurrency["DM"].ToString(); } void OnError(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); } void Start() { #if UNITY_ANDROID AndroidLogin (PlayFabSettings.TitleId); #else Login(PlayFabSettings.TitleId); #endif //Initializations scoreTextAnim = scoreText.GetComponent<Animation>(); tokenTextAnim = tokenText.GetComponent<Animation>(); bonusScoreTextAnim = bonusScoreText.GetComponent<Animation>(); bonusScoreTextAnim2 = bonusScoreText2.GetComponent<Animation>(); Invoke("IncrementScore", 0.1f); //Starts to increase the score } public void IncrementScore(int value) //Increments score by a given value and there is a congratulation text (Collision script calls this function) { if (!FindObjectOfType<Collision>().gameIsOver) { score += value; scoreText.text = score.ToString(); scoreTextAnim.Play(); bonusScoreText.text = bonusTexts[Random.Range(0, bonusTexts.Length)].ToString() + "\n+ " + value.ToString(); bonusScoreTextAnim.Play(); FindObjectOfType<AudioManager>().ScoreSound(); Debug.Log("dima bomjara"); } } public void IncrementScore(int value, int text) //Increments score by a given value and there can be a congratulation text (Collision script calls this function) { if (!FindObjectOfType<Collision>().gameIsOver) { score += value; scoreText.text = score.ToString(); scoreTextAnim.Play(); bonusScoreText2.text = value.ToString(); bonusScoreTextAnim2.Play(); FindObjectOfType<AudioManager>().ScoreSound(); Debug.Log("ladalsdasdasd"); } } public void IncrementScore() //Increments score by one after every x seconds automatically { if (!FindObjectOfType<Collision>().gameIsOver) { score++; scoreText.text = score.ToString(); Invoke("IncrementScore", 0.1f); } } public void IncrementToken() { if (FindObjectOfType<GameManager>().gameIsOver == false) //If the game is not over { var request = new AddUserVirtualCurrencyRequest{ VirtualCurrency = "DM", Amount = 1 }; PlayFabClientAPI.AddUserVirtualCurrency(request, OnGrantVirutualCurrencySuccess, OnError); GetVirtualCurrentcies(); tokenTextAnim.Play(); //Plays tokenTextAnim FindObjectOfType<AudioManager>().TokenSound(); //Plays tokenSound } } public void IncrementToken(int countOfToken) { if (FindObjectOfType<GameManager>().gameIsOver == false) //If the game is not over { var request = new AddUserVirtualCurrencyRequest{ VirtualCurrency = "DM", Amount = 1 }; PlayFabClientAPI.AddUserVirtualCurrency(request, OnGrantVirutualCurrencySuccess, OnError); GetVirtualCurrentcies(); tokenTextAnim.Play(); //Plays tokenTextAnim FindObjectOfType<AudioManager>().TokenSound(); //Plays tokenSound } } void OnGrantVirutualCurrencySuccess(ModifyUserVirtualCurrencyResult result) { // } },
Hello everyone, I ran into such a problem.
When viewing ads, it is rewarded in different ways (two or four), although I put one each.
The translation may be incorrect (translator).
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using PlayFab; using PlayFab.ClientModels; using Newtonsoft.Json; public class ScoreManager : MonoBehaviour { public TextMeshProUGUI scoreText, tokenText, bonusScoreText, bonusScoreText2; private Animation scoreTextAnim, tokenTextAnim, bonusScoreTextAnim, bonusScoreTextAnim2; [HideInInspector] public int score = 0; private string[] bonusTexts = new string[] { "Amazing", "Nice shot", "Rampage", "Great one", "Fantastic", "Unbelievable", "Great", "Nice", "Impressive" }; public string PlayFabId; //это логин :) void Login(string titleId) { LoginWithCustomIDRequest request = new LoginWithCustomIDRequest () { TitleId = titleId, CreateAccount = true, CustomId = SystemInfo.deviceUniqueIdentifier }; PlayFabClientAPI.LoginWithCustomID (request, (result) => { PlayFabId = result.PlayFabId; Debug.Log ("Got PlayFabID: " + PlayFabId); if (result.NewlyCreated) { Debug.Log ("(new account)"); } else { Debug.Log ("(existing account)"); GetVirtualCurrentcies(); } }, (error) => { Debug.Log ("Error logging in player with custom ID:"); }); } void AndroidLogin(string titleId) { LoginWithAndroidDeviceIDRequest request = new LoginWithAndroidDeviceIDRequest () { TitleId = titleId, CreateAccount = true, AndroidDeviceId = SystemInfo.deviceUniqueIdentifier }; PlayFabClientAPI.LoginWithAndroidDeviceID (request, (result) => { PlayFabId = result.PlayFabId; Debug.Log ("Got PlayFabID: " + PlayFabId); if (result.NewlyCreated) { Debug.Log ("(new account)"); } else { Debug.Log ("(existing account)"); GetVirtualCurrentcies(); } }, (error) => { Debug.Log ("Error logging in player with custom ID:"); }); } // тут логин закончился void GetVirtualCurrentcies() { PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), GetLol, OnError); } void GetLol(GetUserInventoryResult result) { tokenText.text = result.VirtualCurrency["DM"].ToString(); } void OnError(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); } void Start() { #if UNITY_ANDROID AndroidLogin (PlayFabSettings.TitleId); #else Login(PlayFabSettings.TitleId); #endif //Initializations scoreTextAnim = scoreText.GetComponent<Animation>(); tokenTextAnim = tokenText.GetComponent<Animation>(); bonusScoreTextAnim = bonusScoreText.GetComponent<Animation>(); bonusScoreTextAnim2 = bonusScoreText2.GetComponent<Animation>(); Invoke("IncrementScore", 0.1f); //Starts to increase the score } public void IncrementScore(int value) //Increments score by a given value and there is a congratulation text (Collision script calls this function) { if (!FindObjectOfType<Collision>().gameIsOver) { score += value; scoreText.text = score.ToString(); scoreTextAnim.Play(); bonusScoreText.text = bonusTexts[Random.Range(0, bonusTexts.Length)].ToString() + "\n+ " + value.ToString(); bonusScoreTextAnim.Play(); FindObjectOfType<AudioManager>().ScoreSound(); Debug.Log("dima bomjara"); } } public void IncrementScore(int value, int text) //Increments score by a given value and there can be a congratulation text (Collision script calls this function) { if (!FindObjectOfType<Collision>().gameIsOver) { score += value; scoreText.text = score.ToString(); scoreTextAnim.Play(); bonusScoreText2.text = value.ToString(); bonusScoreTextAnim2.Play(); FindObjectOfType<AudioManager>().ScoreSound(); Debug.Log("ladalsdasdasd"); } } public void IncrementScore() //Increments score by one after every x seconds automatically { if (!FindObjectOfType<Collision>().gameIsOver) { score++; scoreText.text = score.ToString(); Invoke("IncrementScore", 0.1f); } } public void IncrementToken() { if (FindObjectOfType<GameManager>().gameIsOver == false) //If the game is not over { var request = new AddUserVirtualCurrencyRequest{ VirtualCurrency = "DM", Amount = 1 }; PlayFabClientAPI.AddUserVirtualCurrency(request, OnGrantVirutualCurrencySuccess, OnError); GetVirtualCurrentcies(); tokenTextAnim.Play(); //Plays tokenTextAnim FindObjectOfType<AudioManager>().TokenSound(); //Plays tokenSound } } public void IncrementToken(int countOfToken) { if (FindObjectOfType<GameManager>().gameIsOver == false) //If the game is not over { var request = new AddUserVirtualCurrencyRequest{ VirtualCurrency = "DM", Amount = 1 }; PlayFabClientAPI.AddUserVirtualCurrency(request, OnGrantVirutualCurrencySuccess, OnError); GetVirtualCurrentcies(); tokenTextAnim.Play(); //Plays tokenTextAnim FindObjectOfType<AudioManager>().TokenSound(); //Plays tokenSound } } { }}