- Home /
Unity ads are working in the editor but not as apk
using System.Collections; using System.Collections.Generic; using System; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using UnityEngine.Advertisements;
public class Score : MonoBehaviour { public Text scoreText; public Text PlayerName; public GameObject PlayerNameObject; public GameObject WeaponSelect;
private static int staticScore;
private static int staticWeapons;
public int score;
public bool isUI;
public bool isMenu;
static private string Name;
private void Update()
{
if (isMenu != true)
{
if (isUI == false)
{
staticScore = score;
staticWeapons = staticScore;
Name = PlayerName.text;
scoreText.text = score.ToString();
if (PlayerNameObject.activeSelf == true)
{
if (score == 0)
{
SceneManager.LoadScene("MenuScene");
}
}
}
} else
{
WeaponSelect.GetComponent<WeaponSelect>().HowMuchWeapons = PlayerPrefs.GetInt("Weapons", 0);
}
}
public void OpenLevel()
{
SceneManager.LoadScene("MenuScene");
}
private void Start()
{
//PlayerPrefs.SetInt("Weapons", 0);
if (isMenu != true)
{
if (isUI == true)
{
if (staticScore != 0)
{
gameObject.GetComponent<HighscoreTable>().AddHighscoreEntry(staticScore, Name);
staticWeapons = staticScore;
staticScore = 0;
SceneManager.LoadScene("HighScoreScene");
}
}
}
if (isMenu != true)
{
if (isUI == false)
{
if (Advertisement.isSupported)
{
Advertisement.Initialize("3133737", true);
}
StartCoroutine(ShowAdWhenReady());
}
}
else
{
if (staticWeapons >= 50)
{
if (PlayerPrefs.GetInt("Weapons", 0) <= 2)
{
PlayerPrefs.SetInt("Weapons", 2);
}
}
if (staticWeapons >= 100)
{
if (PlayerPrefs.GetInt("Weapons", 0) <= 3)
{
PlayerPrefs.SetInt("Weapons", 3);
}
}
if (staticWeapons >= 300)
{
if (PlayerPrefs.GetInt("Weapons", 0) <= 4)
{
PlayerPrefs.SetInt("Weapons", 4);
}
}
}
}
IEnumerator ShowAdWhenReady()
{
while (!Advertisement.isInitialized || !Advertisement.IsReady())
yield return null;
Advertisement.Show("Banner");
}
}
Comment