Hi James,
Ok, this is more useful. You are getting NullReferenceExceptions, and they seem to stem from a method on your Defender class called AddStarFive which receives a parameter of type int
named amountFive.
The original course code looked like this;
public void AddStars(int amount)
{
starDisplay.AddStars(amount);
}
Does yours differ in any way? If not, the only obviously thing in this code which could be a null reference would be starDisplay
.
This was originally a private variable which was the initialised in the Start
method, here’s the original code;
using UnityEngine;
public class Defender : MonoBehaviour
{
public int starCost = 100;
private StarDisplay starDisplay;
/// <summary>
/// Initialise
/// </summary>
private void Start()
{
starDisplay = GameObject.FindObjectOfType<StarDisplay>();
}
/// <summary>
/// Adds the specified number of stars to the player's star count
/// </summary>
/// <param name="amount">The amount of stars to add</param>
public void AddStars(int amount)
{
starDisplay.AddStars(amount);
}
}
Also, I note that the error will appear when ever I click, which may suggest an issue with the player input handling.
Lets start here and see what you find, if you are not entirely sure, post up the full code from your Defender.cs file and I’ll take a look