C
C#8mo ago
MRW419

❔ So i'm learning how to transition from one level to another and I got this error.

Would anyone know how to fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Score : MonoBehaviour
{
public Text scoreDisplay;
public int threeStars = 3;
public int twoStars = 5;
public Animator scoreAnimator;
public int nextLevel = 0;

public void EndLevel()
{
Cannon cannon = FindObjectOfType<Cannon>();

if (cannon)
{
int numProjectiles = cannon.numProjectiles;

if (numProjectiles < threeStars)
{
print("Three Stars!");
scoreDisplay.text = "Three Stars!";
scoreAnimator.SetInteger("Stars", 3);
}
else if (numProjectiles < twoStars)
{
print("Two Stars!");
scoreDisplay.text = "Two Stars!";
scoreAnimator.SetInteger("Stars", 2);
}
else
{
print("One Star!");
scoreDisplay.text = "One Star! Try Again!";
scoreAnimator.SetInteger("Stars", 1);
}
NextLevel();

}

void NextLevel()
{
SceneManager.LoadScene(nextLevel);
}

}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Score : MonoBehaviour
{
public Text scoreDisplay;
public int threeStars = 3;
public int twoStars = 5;
public Animator scoreAnimator;
public int nextLevel = 0;

public void EndLevel()
{
Cannon cannon = FindObjectOfType<Cannon>();

if (cannon)
{
int numProjectiles = cannon.numProjectiles;

if (numProjectiles < threeStars)
{
print("Three Stars!");
scoreDisplay.text = "Three Stars!";
scoreAnimator.SetInteger("Stars", 3);
}
else if (numProjectiles < twoStars)
{
print("Two Stars!");
scoreDisplay.text = "Two Stars!";
scoreAnimator.SetInteger("Stars", 2);
}
else
{
print("One Star!");
scoreDisplay.text = "One Star! Try Again!";
scoreAnimator.SetInteger("Stars", 1);
}
NextLevel();

}

void NextLevel()
{
SceneManager.LoadScene(nextLevel);
}

}
}
No description
11 Replies
jcotton42
jcotton428mo ago
what's line 26?
MRW419
MRW4198mo ago
To display star on Ui
jcotton42
jcotton428mo ago
no, what code is on line 26 discord pastes don't have line numbers, and I'm not counting them manually
SinFluxx
SinFluxx8mo ago
scoreDisplay.Text = "Three Stars!"; I think 😄
jcotton42
jcotton428mo ago
you think? your IDE/editor has line numbers (or at least it should, turn them on if it doesn't)
SinFluxx
SinFluxx8mo ago
I'm not op 🙂
jcotton42
jcotton428mo ago
in any case, that means that scoreDisplay is null "not op"?
SinFluxx
SinFluxx8mo ago
Right, I'm not the one that posted the thread, I'm just some sucker who manually counted the line numbers because op hadn't responded yet
jcotton42
jcotton428mo ago
... oh lmao, I missed that 😅
MRW419
MRW4198mo ago
Sorry about that, I was getting out of school and yes. Line 26 is scoreDisplay.Text
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.