Hello, hope you’re well. I’m trying to make it so once a timer reaches zero, a Float (which is defined in another script) should have 10 added to it. This isn’t working, and the error I’m getting is “NullReferenceException: Object reference not set to an instance of an object”. Here is the code where the float is defined:
public class SeedNeed : MonoBehaviour
{
public float currentNeed = 15f;
}
And here’s the code which is trying to make it so when the timer (timeLeft) reaches zero, 10 is added to currentNeed in the first script:
public class harvesting : MonoBehaviour
{
public float timeLeft = 10f;
public SeedNeed seeedNeed;
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0)
{
Debug.Log("IM READY TO HARVEST");
seeedNeed.currentNeed += 10;
}
}
}
Please help, this seemed like a simple enough problem, yet it is very difficult to fix. Thanks!