Search Unity

Advertisement.IsReady(). my button's interactable is always false

Discussion in 'Unity Ads & User Acquisition' started by panim0_unity, Feb 23, 2019.

  1. panim0_unity

    panim0_unity

    Joined:
    Nov 13, 2018
    Posts:
    47
    I just want to make this; if an ad is ready to show than user should be available to click this button but this code doesn't make that happen. Please share your knowledge

    Code (CSharp):
    1.  public Text points;
    2.     public static int points1;
    3.     public Button watchbutton;
    4.      void Start()
    5.     {
    6.        
    7.         points.text="Points: "+PlayerPrefs.GetInt("ScoreCmon").ToString();
    8.         if (UnityEngine.Advertisements.Advertisement.IsReady("rewardedVideo") == false)
    9.         {
    10.  
    11.             watchbutton.interactable = false;
    12.             watchbutton.image.color = Color.red;
    13.         }
    14.  
    15.  
    16.     }
    17.      void Update()
    18.     {
    19.         points.text = "Points: " + PlayerPrefs.GetInt("ScoreCmon").ToString();
    20.      
    21.     }
    22.     public void watch()
    23.     {
    24.  
    25.        
    26.             UnityEngine.Advertisements.Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
    27.        
    28.  
    29.  
    30.        
    31.     }
    32.     private void HandleAdResult(ShowResult result)
    33.     {
    34.  
    35.         switch (result)
    36.         {
    37.             case ShowResult.Finished:
    38.                points1= PlayerPrefs.GetInt("ScoreCmon") + 100;
    39.                 PlayerPrefs.SetInt("ScoreCmon",points1);
    40.                 Time.timeScale = 1f;
    41.  
    42.                 break;
    43.             case ShowResult.Skipped:
    44.                
    45.                 break;
    46.             case ShowResult.Failed:
    47.                
    48.                 break;
    49.         }
    50.     }