How can i make it so after watching 2 rewarded ads all the levels in my game are unlocked and playable. Currently i have it so you have to complete the level in order to unlock that level and be able to play it at any given time.
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
CodePudding user response:
You can use the PlayerPrefs system to track the number of ads they've watched. Increment that PlayerPref each time they watch an ad.
Then change your level configuration code to check for that PlayerPref in addition to which levels they've completed.
CodePudding user response:
Unity uses PlayerPrefs to achieve level unlocking.
Level Structure:
Add a script where the level is confirmed to pass.
public int jiesuo;
jiesuo = SceneManager.GetActiveScene().buildIndex;
PlayerPrefs.SetInt("jiesuo", jiesuo);
Then add the level script to the level artboard.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class level : MonoBehaviour
{
Button[] button;
public GameObject panl;
int jiesuo1;
void Start()
{
jiesuo1 = PlayerPrefs.GetInt("jiesuo");
button = new Button[panl.transform.childCount];
for (int i = 0; i < panl.transform.childCount; i )
{
button[i] = panl.transform.GetChild(i).GetComponent<Button>();
}
for (int i = 0; i < button.Length; i )
{
button[i].interactable = false;
}
for (int i = 0; i < jiesuo1 1; i )
{
button[i].interactable = true;
}
}
void Update()
{
}
}
button add:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class levelbutton : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
public void OnStartGame(int SceneNumber)
{
SceneManager.LoadScene(SceneNumber);
}
void Update()
{
}
}