C
C#15mo 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
jcotton4215mo ago
what's line 26?
MRW419
MRW419OP15mo ago
To display star on Ui
jcotton42
jcotton4215mo ago
no, what code is on line 26 discord pastes don't have line numbers, and I'm not counting them manually
SinFluxx
SinFluxx15mo ago
scoreDisplay.Text = "Three Stars!"; I think 😄
jcotton42
jcotton4215mo ago
you think? your IDE/editor has line numbers (or at least it should, turn them on if it doesn't)
SinFluxx
SinFluxx15mo ago
I'm not op 🙂
jcotton42
jcotton4215mo ago
in any case, that means that scoreDisplay is null "not op"?
SinFluxx
SinFluxx15mo 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
jcotton4215mo ago
... oh lmao, I missed that 😅
MRW419
MRW419OP15mo ago
Sorry about that, I was getting out of school and yes. Line 26 is scoreDisplay.Text
Accord
Accord15mo 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.

Did you find this page helpful?