0

我的项目中有两个场景。每个场景只有一个获奖视频。在第一个场景中,一切都很好,但是如果你从第二个场景到第一个场景,我不能给用户奖励,并且 endofRewarded 面板不可见。打赏的正确方法是什么?我怎样才能做到这一点?

Ps:我知道教程在这里。 https://developers.ironsrc.com/ironsource-mobile/unity/rewarded-video-integration-unity/

但是,我是初学者。谢谢你。

这是我的第一个场景的代码:

public class RewardedMain : MonoBehaviour
{
    public string appkey;

    public GameObject endofRewarded, anaEkran;
    // Start is called before the first frame update
    void Start()
    {
        IronSource.Agent.shouldTrackNetworkState(true);
        IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += RewardedVideoAvaibilityChangedEvent;
        IronSourceEvents.onRewardedVideoAdClosedEvent += RewardedVideoAdClosedEvent;
        IronSourceEvents.onRewardedVideoAdRewardedEvent += RewardedVideoAdRewardedEvent;

        //IronSourceEvents.onRewardedVideoAdReadyEvent += OnRewardedVideoAdReady;


    }//END START

    public void showRewarded()
    {
        if (IronSource.Agent.isRewardedVideoAvailable())
        {
            anaEkran.SetActive(false);
            IronSource.Agent.showRewardedVideo("MainRewarded");
        }

      
    }

    void RewardedVideoAdClosedEvent()
    {
        IronSource.Agent.init(appkey, IronSourceAdUnits.REWARDED_VIDEO);
        IronSource.Agent.shouldTrackNetworkState(true);

    }

    void RewardedVideoAvaibilityChangedEvent(bool available)
    {
        bool rewardedVideoAvailability = available;
    }

    void RewardedVideoAdRewardedEvent(IronSourcePlacement ssp)
    {
        PlayerPrefs.SetInt("totalCoin", PlayerPrefs.GetInt("totalCoin") + 150);
        GameObject.Find("GoldNumberText").GetComponent<Text>().text = PlayerPrefs.GetInt("totalCoin").ToString();
        SoundManager.Instance.PlayEarnGoldSound();
        endofRewarded.SetActive(true);

    }
4

1 回答 1

1

我不太确定你的项目是什么样的,所以我会根据你现在给我的信息给出一些提示。您遇到的问题是,当您到达第二个场景时,与此单声道脚本挂钩的对象会消失吗?如果是这样,请将以下代码添加到 awake 中,您的 GameObject 将跨场景存在!

DontDestroyOnLoad(gameObject);
于 2022-02-26T18:56:20.840 回答