I have a “Cubez” prefab (in “Resources” folder) with “SomeScript” script attached.
SomeScript:
#pragma strict
function move(){
yield WaitForSeconds(1.0);
}
In my scene I have an empty GameObject with “GoScript” script attached.
GoScript:
#pragma strict
var test : CallSome;
function Start () {
test = new CallSome();
test.instance = Instantiate(Resources.Load("Cubez", Transform),Vector3(0,0,0), Quaternion.identity) as Transform;
}
function Update () {
if(test.go()){
StartCoroutine(test.getAndMove());
}
}
Plus I have “CallSome” script with “CallSome” class (used by “GoScript” script).
CallSome
#pragma strict
class CallSome{
var instance : Transform;
var i : int;
function CallSome(){
i = 0;
}
function getAndMove(){
var script : SomeScript = instance.GetComponent(SomeScript);
yield script.move();
}
function go() : boolean{
if(i < 6) i++;
return i == 5;
}
}
My GoScript calls “StartCoroutine(test.getAndMove());” that calls “yield script.move();” and Unity crashes (before doing ANYTHING in move() function, neither an eventual Debug.Log(“some”) in the first line).
Why? Please help me ![]()
Just a side note, when using UnityScript (as opposed to C#), you do not need to call
– YokimatoStartCoroutineon yields. I'm not sure if it's related since I typically stick to C#, but it's a suggestion. ([source][1]) [1]: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.StartCoroutine.html