Hi I have two scripts (SimpleJS and SimpleCS). Simple JS is linked on the Empty GameObject.
//SimpleJS.js
private var csComponent;
function Start() {
print("Simple JS Satrt");
csComponent = gameObject.AddComponent("SimpleCS");
csComponent.GetPointsLength();
csComponent.SetNumberOfPoints(10);
csComponent.GetPointsLength();
}
second script:
//SimpleCS.cs
using UnityEngine;
using System.Collections;
public class SimpleCS : MonoBehaviour {
public int[] Points;
void Start() {
print("SimpleCS Start");
Points = new int[0];
}
void GetPointsLength() {
print("SimpleCS Points.LN: "+ Points.Length);
}
void SetNumberOfPoints(int newLn) {
int[] newPoints = new int [newLn];
for(int i=0; i < newLn; i++) {
newPoints[i] = i;
}
Points = newPoints;
}
}
There is problem. SimpleJS start block is processed first and after that is processed Start block from component. That means this in SimpleJS
csComponent.GetPointsLength();
is called, but Start Block from SimpleCS is not declared (ready). And unity tell me this:
Replacing Start() with Awake() in both scripts, everything is OK.
Any idea why Unity do that?