get_transform can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Component:get_transform()
Player:getPos2(Player) (at Assets/Player.cs:20)
Player:DoCheckPlatform() (at Assets/Player.cs:35)
The problem is that I AM calling it from the main thread, so this is more of a bug report?
void FixedUpdate () {
this.transform.Translate (Input.GetAxis("Horizontal") / 1600f, 0, 0);
System.Threading.Thread thread = new System.Threading.Thread (DoCheckPlatform);
thread.Start ();
}
Vector3 getPos2 (Player obj) {
return obj.transform.position;
}
float minDistance = Mathf.Infinity;
GameObject close = null;
void DoCheckPlatform () {
if (Physics2D.BoxCastAll(getPos2(this), Vector2.one * 1.1f, 0, Vector2.zero).Length > 1) {
for (int i = 0; i < ml.gameObjects.Length; i++) {
if (ml.gameObjects != null) {
if (ml.game.game [ml.LevelIndex].map _.Type != type.Finish && ml.game.game [ml.LevelIndex].map *.Type != type.Start) {*_
_ GameObject col = ml.gameObjects ;
* if (Vector2.Distance (getPos(col), getPos(this.gameObject)) < minDistance) {
minDistance = Vector2.Distance (getPos(col), getPos(this.gameObject));
close = col;
}
}
}
}*_
* }*
* }*