Please can somebody tell me how I could switch scenes by collececting all the collectible items. The game is like Roll a Ball but different.
PLZ REPLY QUICK. PLEASE!!
Make an empty gameObject in the scene and call it GameManager
here’s it’s code:
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public static GameManager Instance;
public string levelToLoad;
public int collectables;
public int requiredCollectables = 10;
void Awake ()
{
Instance = this;
}
void AddCollectable ()
{
collectables++;
if (collectables >= requiredCollectables)
UnityEngine.SceneManagement.SceneManager.LoadScene(levelToLoad);
}
}
----------------------------
Now make a script called Collectable and put it in every collectable object
Here’s it’s code:
using UnityEngine;
using System.Collections;
public class Collectable : Monobehaviouor {
void Start ()
{
GetComponent<Collider>().isTrigger = true;
}
void OnTriggerEnter ()
{
GameManager.Instance.AddCollectable();
}
}
Whats the first code for??? @Malek-Baker