I am periodically taking a value from one script and adding it to a grand total (totalRev) on another script.
The grand total script:
using UnityEngine;
using System.Collections;
public class player1Base : MonoBehaviour
{
public static player1Base S;
public int totalRev = 0;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
The sub-total script:
void Deposit()
{
if(pRev != 0)
{
nextDeposit = Time.time+(lastDeposit/rOP);
print ("deposit" );
player1Base.S.totalRev += pRev;
}
}
The timing works fine, but every five seconds (whenever a transfer is supposed to occur) I get a NullRef as this is not set to an instance of an object. There is only one instance of this script and my (limited) understanding, is that by setting up a Singleton I can access this script from anywhere in my code. I’m re-using this concept from a tutorial I’ve done that works fine, but obviously I’m doing something wrong here. The interesting thing is I’m getting a run-time error not a compile error.
Any help would be appreciated.