I have script (ManagerScript) where I have PlayRewardedAd void which plays rewarded ad , but when I attached this components to other script nothing happens (when player dies for 15th - by hitting a bottom wall- ad won’t play,instead ball just bounces up from wall).So Unity recognizes some action on 15th death ,but not correct action.Here’s ballscript :
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class BallScript : MonoBehaviour
{
private ManagerAds ads;
public Vector2 startForce;
static int times = 0;
public Text goverText;
public Vector3[] positions;
public Rigidbody2D rb;
void Start()
{
int randomNumber = Random.Range(0, positions.Length);
transform.position = positions[randomNumber];
times = PlayerPrefs.GetInt("Played:", times);
rb.AddForce(startForce, ForceMode2D.Impulse);
ads = FindObjectOfType<ManagerAds>();
}
void Update()
{
PlayerPrefs.SetInt("Played:", times);
goverText.text = "Played:" + times.ToString();
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.name == "wall_bottom")
{
times++;
if (times == 15)
{
ads.PlayRewardedAd();
}
SceneManager.LoadScene("wfvv");
}
}
}