Okay I have 2 scripts, one generates a list of Vector3’s. The second checks to see if a Vector3 exists on the list. No errors on console till I try to run the game. but when I do it throws a null ref.
both scripts are using “using System.Collections.Generic;”
script 1:
public class Script1 : MonoBehaviour {
public List<Vector3> testList= new List<Vector3>();
..............
void runonce(){
for (int ix = 0; ix < 10; ix++) {
for (int iz = 0; iz < 10; iz++) {
for (int iy = 0; iy < 10; iy++) {
current = new Vector3 (ix, iy, iz);
if (testList.Contains (current)) {
............................................
}
this first script runs fine on its own and produces no errors. however, script 2…
public class Script2: MonoBehaviour {
GameObject object;
Script1 script1;
void Start () {
GameObject object = GameObject.Find("object");
Script1 script1 = object.GetComponent<Script1>();
}
.......................
checkForChanges(){
Vector3 thisVoxelPosition = this.transform.position;
int thisX = Mathf.RoundToInt (thisVoxelPosition.x);
int thisY = Mathf.RoundToInt (thisVoxelPosition.y);
int thisZ = Mathf.RoundToInt (thisVoxelPosition.z);
checkedSpace = new Vector3 (thisX, thisY, thisZ + 1);
if (script1.testList.Contains (checkedSpace)) {
checkFront = 0;
} else {
checkFront = 1;
}
}
Btw I know the Mathf.RoundToInt stuff is probably not needed, and I have tried this with
float thisX = thisVoxelPosition.x; ect…
no good. Null Ref on the line
if (script1.testList.Contains…
I’ve also tried if (script1.testList.Exists…