- Home /
Question by
panim0_unity · Feb 24, 2019 at 05:47 PM ·
c#uigameobjectbuttonads
Unity ads , can't we show video by clicking a button?
this watch it is the method that i assigned to my button and it show 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..
public GameObject PlayerDestroy;
public GameObject uiw;
private float t;
public int scene;
[SerializeField] private Transform player;
[SerializeField] private Transform respawnPoint;
public void ModeSelect()
{
StartCoroutine("Wait");
}
private void Start()
{
t = Time.time + 2;
}
void OnCollisionEnter(Collision obj)
{
Debug.Log(Time.time);
if (UnityEngine.Advertisements.Advertisement.IsReady() && Time.time>t)
{
t = Time.time + 2f;
Time.timeScale = 0f;
uiw.SetActive(!uiw.activeSelf);
}
else
{
Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
GameObject.Find("Sphere").SendMessage("Finish2");
GameObject.Destroy(PlayerDestroy);
Invoke("WaitingFunction", 1);
}
}
public void Watchit() {
UnityEngine.Advertisements.Advertisement.Show("rewardedVideo", new ShowOptions() { resultCallback = HandleAdResult });
uiw.SetActive(!uiw.activeSelf);
}
private void HandleAdResult(ShowResult result)
{
switch (result)
{
case ShowResult.Finished:
Time.timeScale = 1f;
GameObject.Destroy(gameObject);
break;
case ShowResult.Skipped:
Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
GameObject.Find("Sphere").SendMessage("Finish2");
GameObject.Destroy(PlayerDestroy);
Invoke("WaitingFunction", 1);
break;
case ShowResult.Failed:
Instantiate(patlama, this.gameObject.transform.position, this.gameObject.transform.rotation);
GameObject.Find("Sphere").SendMessage("Finish2");
GameObject.Destroy(PlayerDestroy);
Invoke("WaitingFunction", 1);
break;
}
}
void WaitingFunction() {
SceneManager.LoadScene(scene);
}
Comment
Answer by panim0_unity · Feb 24, 2019 at 06:43 PM
When i write advertiesment.show inside if statement without calling that method from button it works perfectly but why cant i do the same by pressing button