wie zu warten, für eine bestimmte Anzahl von Sekunden in der Einheit

Ich möchte einen Ladebalken in unity-2d-Spiel durch die Instanziierung 7 Würfel alle 1 Sekunde.
Verwendet habe ich :
yield WaitForSeconds(1);
in der Funktion update nach jedem instanziieren statement, aber es hat nicht funktioniert :(( ich bekam eine Fehlermeldung, die lautet :

Skript-Fehlermeldung : Update() kann nicht ein coroutine.

Andere Idee?

Machte ich eine neue Szene und nannte Sie "verlieren", dann habe ich das Drehbuch schrieb, und befestigte es an der Haupt-Kamera:

#pragma strict

//var loadingBar: Transform;
var loading_bar : GameObject;

function Update()
{
    Instantiate(loadingBar,Vector3(-1.849,-2.9371,2),Quaternion.identity);

    gameTimer();


    Instantiate(loadingBar,Vector3(-1.2909,-2.937,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(-0.5566,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(0.148236,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(0.823772,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(1.440567,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(2.057361,-2.93711,2),Quaternion.identity);

    loadingTimer();

    Application.LoadLevel(1);
}


function OnGUI()
{
    GUI.color = Color.green;
    GUI.Label(Rect(400,350,500,500),"<color=green><size=100>Lose</size></color>");
}

function loadingTimer()
{
    yield WaitForSeconds(1);
}

wie zu warten, für eine bestimmte Anzahl von Sekunden in der Einheit

Ich will diese Würfel erscheinen nach einander von 1 Sekunde, so dass es
Sie scheinen wie ein Ladebalken ...

Ich löste dieses problem, indem auf diese Weise ::

#pragma strict

var loadingBar: Transform;
var finished : boolean = false;

function Update()
{
    loadingTimer();

    if (finished == true)
    {
        Application.LoadLevel(1);
        finished= false;
    }
}


function OnGUI()
{
    GUI.color = Color.green;
    GUI.Label(Rect(295,320,500,500),"<color=green><size=100>Lose</size></color>");

}


function loadingTimer()
{
    Instantiate(loadingBar,Vector3(-1.9,-2.9371,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(-1.3,-2.937,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(-1.3,-2.937,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(-0.7,-2.93711,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(-0.1,-2.93711,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(0.5,-2.93711,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(1.1,-2.93711,2),Quaternion.identity);
    yield WaitForSeconds(0.28);
    Instantiate(loadingBar,Vector3(1.7,-2.93711,2),Quaternion.identity);

    finished= true;
}

InformationsquelleAutor Akari | 2013-10-03

Schreibe einen Kommentar