- Home /
testing the rewarded video unity ads
Below i am giving the codes for my unity ads script. i have made "life" as text in my scene which records the number of lives my player has. irrespective of the number of lives he might have i want to make a button which if pressed will show my rewarded ad and after watching it it shall reward the player with 5 coins. problem is , the "life" counter is in a separate script and am not sure, because even though the button if pressed shows a custom ad in "test"mode, but am not sure if the codes work! i should mention that this is the last mile bottleneck after making a complete app.kindly help me.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Advertisements;
public class unityad : MonoBehaviour { public int lifeleft;
// Use this for initialization
void Start () {
GameObject lifeobject = GameObject.Find("life");
UImanager ui = lifeobject.GetComponent<UImanager>();
lifeleft = ui.life;
lifeleft = lifeleft + 5;
}
// Update is called once per frame
void Update () {
}
public void showad(){
if(Advertisement.IsReady()){
Advertisement.Show ();
}
}
public void HandleAdResult(ShowResult result){
switch (result) {
case ShowResult.Finished:
Debug.Log ("ad finished");
break;
case ShowResult.Skipped:
Debug.Log("ad skipped");
break;
case ShowResult.Failed:
Debug.Log("ad failed");
break;
}
}
}
I'm confused with your question though. Do you want to add coins or life? and you should add it to the variable that holds your life "count" and not the life "UI", right?
Answer by jchester07 · Oct 11, 2017 at 07:56 AM
You should do it from HandleAdResult() method
public void HandleAdResult(ShowResult result){
switch (result) {
case ShowResult.Finished:
lifeleft += 5;
Debug.Log ("ad finished");
break;
case ShowResult.Skipped:
Debug.Log("ad skipped");
break;
case ShowResult.Failed:
Debug.Log("ad failed");
break;
}
}
Check your console for the Debug.Log()
Your answer
