unity ads tutorial

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

// how to start a rewarded ad in unity games after pressign a button
[RequireComponent (typeof (Button))]
public class RewardedAdsButton : MonoBehaviour, IUnityAdsListener {

    #if UNITY_IOS
    private string gameId = "1486551";
    #elif UNITY_ANDROID
    private string gameId = "1486550";
    #endif

    Button myButton;
    public string myPlacementId = "rewardedVideo";

    void Start () {   
        myButton = GetComponent <Button> ();

        // Set interactivity to be dependent on the Placement’s status:
        myButton.interactable = Advertisement.IsReady (myPlacementId); 

        // Map the ShowRewardedVideo function to the button’s click listener:
        if (myButton) myButton.onClick.AddListener (ShowRewardedVideo);

        // Initialize the Ads listener and service:
        Advertisement.AddListener (this);
        Advertisement.Initialize (gameId, true);
    }

    // Implement a function for showing a rewarded video ad:
    void ShowRewardedVideo () {
        Advertisement.Show (myPlacementId);
    }

    // Implement IUnityAdsListener interface methods:
    public void OnUnityAdsReady (string placementId) {
        // If the ready Placement is rewarded, activate the button: 
        if (placementId == myPlacementId) {        
            myButton.interactable = true;
        }
    }

    public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
        // Define conditional logic for each ad completion status:
        if (showResult == ShowResult.Finished) {
            // Reward the user for watching the ad to completion.
        } else if (showResult == ShowResult.Skipped) {
            // Do not reward the user for skipping the ad.
        } else if (showResult == ShowResult.Failed) {
            Debug.LogWarning (“The ad did not finish due to an error.”);
        }
    }

    public void OnUnityAdsDidError (string message) {
        // Log the error.
    }

    public void OnUnityAdsDidStart (string placementId) {
        // Optional actions to take when the end-users triggers an ad.
    } 
}

4.5
10
Fionnbharr 175 points

                                    using UnityEngine;
using UnityEngine.Advertisements;

public class InitializeAdsScript : MonoBehaviour { 

    string gameId = &quot;1234567&quot;;
    bool testMode = true;

    void Start () {
        Advertisement.Initialize (gameId, testMode);
    }
}

4.5 (10 Votes)
0
4.2
5

                                    using UnityEngine;
using UnityEngine.Advertisements;

// how to initalize ads in unity games
public class InitializeAdsScript : MonoBehaviour { 

    #if UNITY_IOS
    private string gameId = &quot;1486551&quot;;
    #elif UNITY_ANDROID
    private string gameId = &quot;1486550&quot;;
    #endif
    
    bool testMode = true;

    void Start () {
        Advertisement.Initialize (gameId, testMode);
    }
}

4.2 (5 Votes)
0
3.86
7
Alphonso 100 points

                                    using UnityEngine;
using UnityEngine.Advertisements;

// how to make rewarded scripts autometically in unity games
public class RewardedAdsScript : MonoBehaviour, IUnityAdsListener { 

    #if UNITY_IOS
    private string gameId = &quot;1486551&quot;;
    #elif UNITY_ANDROID
    private string gameId = &quot;1486550&quot;;
    #endif
    
   
    string myPlacementId = &quot;rewardedVideo&quot;;
    bool testMode = true;

    // Initialize the Ads listener and service:
    void Start () {
        Advertisement.AddListener (this);
        Advertisement.Initialize (gameId, testMode);
    }

    // Implement IUnityAdsListener interface methods:
    public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
        // Define conditional logic for each ad completion status:
        if (showResult == ShowResult.Finished) {
            // Reward the user for watching the ad to completion.
        } else if (showResult == ShowResult.Skipped) {
            // Do not reward the user for skipping the ad.
        } else if (showResult == ShowResult.Failed) {
            Debug.LogWarning (&quot;The ad did not finish due to an error.&quot;);
        }
    }

    public void OnUnityAdsReady (string placementId) {
        // If the ready Placement is rewarded, show the ad:
        if (placementId == myPlacementId) {
            Advertisement.Show (myPlacementId);
        }
    }

    public void OnUnityAdsDidError (string message) {
        // Log the error.
    }

    public void OnUnityAdsDidStart (string placementId) {
        // Optional actions to take when the end-users triggers an ad.
    } 
}

3.86 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Unity Ads example unity ads tutorial 2021 unity ads guide how to make unity ads unity hauwei ads tutorial 2020 unity setup ads how to make ads in unity how does unity ads work simple ads in unity unity ads ads tutorial unity how to integreate adds in unity ads in unity google ads unity unity ads class unity ads clas what does unity ad listener unity facebook ads tutorial code unity ads sample unity ads banner integration video ads unity unity video ads script add unity ads to game Unity Tutorials unity ads placements tutorial unity ads tutoriall unity tutorial unity ads script example how to use unity ads handle results unity monetization example unity ad tutorial unity 2020 tutorial unity tutorials 2020 unity ad advertisement c# integrate unity ads unity c# script UNITY ADS TUTIRIAL how to add adds unity unity ads enable plateforme unity ads manager how to create ad video unity how to create unity ad videos unity ads script how to use rewarded ads in untiy unity ads how to add ads to project unity ads code unity add adds unity ads code sample unity ads tutorial 2020 How to enable Unity 3d ads unity ad integration unity video ads unity setting up adds unity ads integration implementing ads in unity game unity ads rewarded video unity implement ad unity implement add unity play advertisement unity advertisement script unity ads listener how to implement code after unity ads skip how to implement ads in unity 2020 unity ads tutorial rewarded ads unity ads unity how to make ads unity ads implementation unity ads test mode check iunityadslistener example unity ad code how to use unity ads how to integrate unity ads in unity unity cAll ad on click ad unity click to watch ad unity
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source