Hi, cant figure out why this C# script is not working. I just want to go to a new scene after collecting 6 coins/selfies This the code I have on my player.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class CoinController : MonoBehaviour {
public static int coinCount = 0;
void OnGUI()
{
string coinText = "Selfies: " + coinCount;
GUI.Box (new Rect(Screen.width - 150, 20, 130, 20), coinText);
}
void Update ()
{
if (coinCount >= 6)
SceneManager.LoadScene (1);
}
}
And this one is on the coin/selfie
using UnityEngine;
using System.Collections;
public class PickupItem : MonoBehaviour
{
AudioSource _audioSource;
public AudioClip _audioClip;
public GameObject _particle;
void Start()
{
_audioSource = GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Renderer[] renderers = GetComponentsInChildren<Renderer>();
foreach (Renderer r in renderers)
r.enabled = false;
_audioSource.PlayOneShot(_audioClip);
CoinController.coinCount++;
Destroy(gameObject, _audioClip.length);
}
}
}
}
Thanks in advance!