question

Vyacheslav avatar image
Vyacheslav asked

Several pieces are added(rewarded ads),Several pieces are added, rewarded ads

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)

Video

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).

video

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
        }
    }
    { }}
unity3d
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image Gosen Gao commented ·

If I understand correctly, you are calling method IncrementToken to increase 1 DM to the player's virtual currency, but the result is not as expected, sometimes it increases by 1, sometimes it increases by 2. I don't see anything incorrect with IncrementToken, could you please add a debug to the method IncrementToken to see how many times this method is executed?

0 Likes 0 ·
Vyacheslav avatar image Vyacheslav Gosen Gao commented ·
0 Likes 0 ·
Vyacheslav avatar image Vyacheslav Vyacheslav commented ·

the reward calls twice

0 Likes 0 ·

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

According to the video you post, sometimes, the DM is added twice at the same time. This should be related to the trigger mechanism of this method, please check your code to find out why this method can be triggered twice at the same time.


dm.png (34.2 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.