【问题标题】:Unity3D Google admob: User is reward twice (or more) hackUnity3D Google admob:用户奖励两次(或更多)hack
【发布时间】:2020-01-21 00:27:07
【问题描述】:

我创建了一个每日奖励系统,其中玩家每天可以获得大约 3 个 500 硬币,例如1/3金币。我用Admob Unity Plugin给玩家显示奖励视频,点击按钮获得500金币,按钮可以点击3次,玩家每观看一次奖励视频,获得500金币。

我的问题:

1:如果用户第一次点击奖励按钮并完整观看奖励视频,我的int将增加到1并且玩家奖励500个硬币 - (所以是500个硬币的1/3)

2:如果用户第二次点击了奖励按钮,但又决定关闭奖励视频,int将增加,玩家奖励500 个硬币 - (仍然是 500 个硬币的 1/3)

3:但如果用户决定点击奖励按钮,然后决定完整观看新的奖励视频,int 将增加 2(而不是 1)并且玩家现在奖励 1,000 金币(而不是 500)-(现在是 3/3 有 1,500 金币)

注意:此顺序不是特定的,用户可以从一开始或在 int 达到 3/3 之前执行此方法,并且用户想要多次执行此方法,只需关闭奖励视频很多时间(未完成视频)直到满意,然后将奖励视频完整观看 3 次。

我不会包含我的每日奖励脚本,因为我不认为它会导致我的问题。 请问哪位大神能帮帮我,谢谢!!!!!!

这是我的奖励脚本:

    {
        public Admob ad;
        public int clickInt = 0;
        public Text clickText;
        public Image coinImage;
        public Button rewardButton;


    void Awake()
    {
            if (PlayerPrefs.HasKey("amount"))
            {
                clickInt = PlayerPrefs.GetInt("amount");
            }
     }


      void Start ()
        {
#if UNITY_EDITOR
    Debug.Log("Unable to play ad in the EDITOR");
       if (clickInt == 1) { 
            clickText.text = "1/3 Daily uses"; 
       } else if (clickInt == 2) { 
            clickText.text = "2/3 Daily uses"; 
       } else if (clickInt >= 3) {
            clickInt = 3;
       }

       if (clickInt == 3) {
           clickText.text = "3/3 Daily uses";
       }
#elif UNITY_ANDROID

       if (clickInt == 1) { 
           clickText.text = "1/3 Daily uses"; 
       } else if (clickInt == 2) { 
           clickText.text = "2/3 Daily uses"; 
       } else if (clickInt >= 3) {
           clickInt = 3;
       }

       if (clickInt == 3) {
           clickText.text = "3/3 Daily uses";
       }     
#endif
      }

    // Update is called once per frame
    void Update()
    {
#if UNITY_EDITOR
    Debug.Log("Unable to play ad in the EDITOR");
       if (clickInt == 1) { 
            clickText.text = "1/3 Daily uses"; 
       } else if (clickInt == 2) { 
            clickText.text = "2/3 Daily uses"; 
       } else if (clickInt >= 3) {
            clickInt = 3;
       }

       if (clickInt == 3) {
           clickText.text = "3/3 Daily uses";
       }
#elif UNITY_ANDROID

        ad = Admob.Instance ();
       if (ad.isRewardedVideoReady ()) {
          coinImage.enabled = true;
       } else {
          ad.loadRewardedVideo ("ca-app-pub-…………………/……………"); 
          coinImage.enabled = false;
       }

       if (clickInt == 1) { 
           clickText.text = "1/3 Daily uses";
           rewardButton.interactable = true; 
       } else if (clickInt == 2) { 
           clickText.text = "2/3 Daily uses";
           rewardButton.interactable = true;  
       } else if (clickInt >= 3) {
           clickInt = 3;
       }

       if (clickInt == 3) {
           clickText.text = "3/3 Daily uses";
           rewardButton.interactable = false; 
       }     
#endif
      }




       public void Free_500_Coins()
        {
#if UNITY_EDITOR
        Debug.Log("Unable to play ad in the EDITOR");
         clickInt += 1;
        ShopManager.Playercurrency += 500;
#elif UNITY_ANDROID
        if (ad.isRewardedVideoReady ()) {
            Admob.Instance().interstitalRewardHandler += onInterstitalRewardVideoEvent;
            coinImage.enabled = true;
        ad.showRewardedVideo ();
    } else {
            ad.loadRewardedVideo ("ca-app-pub-............/..........."); 
            coinImage.enabled = false;
        }
#endif
    }


    void onInterstitalRewardVideoEvent(string eventNames, string msgs)
    {
        if (eventNames == "onRewarded")
        {
                Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
                Debug.Log("Well Done! You got 500 coins");
                clickInt += 1;
                ShopManager.Playercurrency += 500;
                Debug.Log("handler AdmobEventsHandler---" + eventNames + "   " + msgs);
        }
     }

    public void OnDestroy()
    {
        Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
    }

   }```   

【问题讨论】:

    标签: unity3d admob


    【解决方案1】:

    您必须使用 + & - 从所有作业中删除“onInterstitalRewardVideoEvent”,并在这些行下方添加。

     void OnEnable() {
        Admob.Instance().interstitalRewardHandler += onInterstitalRewardVideoEvent;
    }
    void OnDisable() {
        Admob.Instance().interstitalRewardHandler -= onInterstitalRewardVideoEvent;
    }
    

    【讨论】:

    • 谢谢您的帮助。我遇到了一个问题,之前有人说我必须这样做,但我想它没有帮助!但再次感谢你,它真的很有帮助!
    【解决方案2】:

    只需将if (ad.isRewardedVideoReady ()) { 更改为if (ad.isRewardedVideoReady () && !coinImage.enabled) {

    向调用Free_500_Coins 的按钮发送垃圾邮件将导致两次调用添加处理程序。

    【讨论】:

    • 我不会向调用 free_500_coins 的按钮发送垃圾邮件,因为我只按了一次按钮。该按钮永远不会关闭,它只能交互 - 真或假。硬币图像是我想要打开和关闭的其他东西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多