you mead csripts
void OnTriggerEnter2D(Collider2D col)
{
if (LayerMask.LayerToName (col.gameObject.layer).Equals (NinjaRopeConst.PLAYER_CHILD))
{
if (GameOverDialog != null) {
GameOverDialog.SetActive (true);
}
gameOver = true;
//loadCount ++;
Destroy (col.gameObject.transform.parent.gameObject);
if (loadCount % 3 == 0) // only show ad every third time
{
///ShowAd();
LoadTheLevel();
}
}
}
public void LoadTheLevel()
{
LevelGenerate = Random.Range(1, 5);
SceneManager.LoadScene(LevelGenerate);
}
this is a death by player count every 3rd time player dies public void LoadTheLevel() loads random scene.
but the if (loadCount % 3 == 0) doesn’t work every 3rd death,1st,7th death yes
entire code-------
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
namespace NinjaRope
{
public class GameOverController : MonoBehaviour
{
public GameObject GameOverDialog;
private bool gameOver = false;
static int loadCount = 0;
public int LevelGenerate;
void Awake()
{
if (GameOverDialog != null)
{
GameOverDialog.SetActive (false);
}
else
{
Debug.Log ("*** Add a GameOver-Dialog to the uGUI ***");
}
}
//void Start()
//{
//loadCount = 0;
//}
void OnTriggerEnter2D(Collider2D col)
{
if (LayerMask.LayerToName (col.gameObject.layer).Equals (NinjaRopeConst.PLAYER_CHILD))
{
if (GameOverDialog != null)
{
GameOverDialog.SetActive (true);
}
gameOver = true;
//loadCount ++;
Destroy (col.gameObject.transform.parent.gameObject);
if (loadCount % 3 == 0) // only show ad every third time
{
///ShowAd();
LoadTheLevel();
}
}
}
public void LoadTheLevel()
{
LevelGenerate = Random.Range(1, 5);
SceneManager.LoadScene(LevelGenerate);
}
void Update()
{
if (gameOver)
{
#if UNITY_EDITOR
if (Input.GetMouseButtonDown (0))
{
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
}
#endif
if (Input.touchCount > 0)
{
foreach (Touch t in Input.touches)
{
if (t.phase == TouchPhase.Began)
{
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
}
}
}
}
}
}
}