Search Unity

Unity ads , can't we show video by clicking a button?

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

  1. panim0_unity

    panim0_unity

    Joined:
    Nov 13, 2018
    Posts:
    47
    this watchit is the method that i assigned to my button and it shows the ads but it doesn't do anything from handleresult. game just keeps running, after finishing the video it should destroy the object but it doesn't..

    Code (CSharp):
    1. public GameObject PlayerDestroy;
    2.      public GameObject uiw;
    3.      private float t;
    4.    
    5.      public int scene;
    6.      [SerializeField] private Transform player;
    7.      [SerializeField] private Transform respawnPoint;
    8.      public void ModeSelect()
    9.      {
    10.          StartCoroutine("Wait");
    11.      }
    12.      private void Start()
    13.      {
    14.          t = Time.time + 2;
    15.      }
    16.      void OnCollisionEnter(Collision obj)
    17.      {
    18.          Debug.Log(Time.time);
    19.          if (UnityEngine.Advertisements.Advertisement.IsReady() && Time.time>t)
    20.          {
    21.              t = Time.time + 2f;
    22.              Time.timeScale = 0f;
    23.            
    24.              uiw.SetActive(!uiw.activeSelf);
    25.          }
    26.          else
    27.          {
    28.              Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
    29.              GameObject.Find("Sphere").SendMessage("Finish2");
    30.              GameObject.Destroy(PlayerDestroy);
    31.            
    32.              Invoke("WaitingFunction", 1);
    33.            
    34.          }
    35.      }
    36.      public void Watchit() {
    37.          UnityEngine.Advertisements.Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
    38.          uiw.SetActive(!uiw.activeSelf);
    39.      }
    40.      private void HandleAdResult(ShowResult result)
    41.      {
    42.          switch (result)
    43.          {
    44.              case ShowResult.Finished:
    45.                  Time.timeScale = 1f;
    46.                  GameObject.Destroy(gameObject);
    47.                  break;
    48.              case ShowResult.Skipped:
    49.                  Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
    50.                  GameObject.Find("Sphere").SendMessage("Finish2");
    51.                  GameObject.Destroy(PlayerDestroy);
    52.                  Invoke("WaitingFunction", 1);
    53.                  break;
    54.              case ShowResult.Failed:
    55.                  Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
    56.                  GameObject.Find("Sphere").SendMessage("Finish2");
    57.                  GameObject.Destroy(PlayerDestroy);
    58.                  Invoke("WaitingFunction", 1);
    59.                  break;
    60.          }
    61.      }
    62.      void WaitingFunction() {
    63.        
    64.          SceneManager.LoadScene(scene);
    65.        
    66.      }
     
  2. panim0_unity

    panim0_unity

    Joined:
    Nov 13, 2018
    Posts:
    47
    It supposed to destroy the object that player touched, after watching the video it just does Time.timeScale=1f;,when I place that advertisement.show inside my if statement it works perfectly