Thanks, I didn't know about awake nor didn't have that at all. Now it compiles but at runtime I get:
NullReferenceException: Object reference not set to an instance of an object
BSplineSurface.Init () (at Assets/BSplineSurface.cs:64)
The last line below is 64. Many thanks again in advance.
public class BSplineSurface : ScriptableObject {
/*
* THESE VALUES MUST BE SET BEFORE CALCULATING
*/
//size of the control net (e.g. 3x4 net)
public int NI = 4; //setting these to high can crash unity
public int NJ = 4;
//Grid of control points
public Vector3[,] controlGrid;
//The degree in each direction
public int TI = 3;
public int TJ = 3;
//output GRID resolution (e.g. 30x40)
public int RESOLUTIONI = 150; //setting these to high can crash unity
public int RESOLUTIONJ = 150;
//the output Grid
public Vector3[,] outputGrid;
public BSplineMath bmath;
/*
* INTERNAL VALUES
*/
//internal knots in each direction
private int[] knotsI;
private int[] knotsJ;
//internal variables
private int i, j, ki, kj;
private float intervalI, incrementI, intervalJ, incrementJ, bi, bj;
//FUNCTIONS
void Awake() // NOTE: Unity always calls Awake on its main thread.
{
bmath = ScriptableObject.CreateInstance("BSplineMath") as BSplineMath;
}
//constructor
public BSplineSurface()
{
Init();
}
//MUST BE CALLED FIRST
public void Init () {
controlGrid = new Vector3[NI+1,NJ+1];
outputGrid = new Vector3[RESOLUTIONI, RESOLUTIONJ];
//init step size (the increment steps)
incrementI = (NI-TI+2) / ((float)RESOLUTIONI - 1);
incrementJ = (NJ-TJ+2) / ((float)RESOLUTIONJ - 1);
//Calculate KNOTS
knotsI = bmath.SplineKnots(NI, TI);