Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Victory menu not working - NullReferenceException

$
0
0
I'm quite new to unity, I'm currently making my very first game. So this might be a stupid question. Anyway, I've finished my first level on my game however I need a victory menu for it once the player has completed it. But it doesn't not seem to work for me somehow, I am quite certain that there isn't a flaw in my script but then again, I am kind of new to unity. Everytime I reach the score required to complete the level I get the following error: NullReferenceException: Object reference not set to an instance of an object PointsCounter.Update () (at Assets/Scripts/PointsCounter.cs:39)... Here's my scripts: using UnityEngine; using System.Collections; using UnityEngine.Audio; using UnityEngine.SceneManagement; public class PointsCounter : MonoBehaviour { public UnityEngine.UI.Text pointsDisplay; public AudioClip coinPickUp; private VictoryMenu victoryMenu; private AudioSource source; public int amountOfPoints; private void Awake() { source = GetComponent(); } void Start() { victoryMenu = VictoryMenu.FindObjectOfType(); pointsDisplay.text = "Points: " + amountOfPoints; } public void AddPoints(int points) { source.PlayOneShot(coinPickUp); amountOfPoints += points; pointsDisplay.text = "Points: " + amountOfPoints; } private void Update() { if (amountOfPoints >= 1000) { Debug.Log("Victory! You completed the level."); victoryMenu.Victory(); } } } using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; public class VictoryMenu : MonoBehaviour { public Text victoryMessage; public Text nextLevel; public Text restartLevel; public Text quitGame; private void Start() { gameObject.SetActive(false); } public void Victory() { victoryMessage.text = "Wohoo! \nYou completed the level!"; nextLevel.text = "NEXT LEVEL"; restartLevel.text = "RESTART"; quitGame.text = "QUIT GAME"; gameObject.SetActive(true); } public void LoadNextLevel() { SceneManager.LoadScene("Scene2"); } public void RestartCurrentLevel() { SceneManager.LoadScene("Scene1"); } public void QuitGame() { Application.Quit(); } }

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>