Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno Jak stopnout javascript

Mám tento kód:

var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;

function Start(){
changeTexture();

}
function Update () {

}

function changeTexture () {


var i= 20;
for(i=20;i>0;i++) {

yield WaitForSeconds(20);
renderer.material.mainTexture = texture1;

yield WaitForSeconds(20);
renderer.material.mainTexture = texture2;

yield WaitForSeconds(20);
renderer.material.mainTexture = texture3;

}

}

Když ho spustím, mění obrázky pořád dokola. Kam mám vložit stop, nebo něco tak, aby se script vykonal pouze jednou a neopakoval se pořád dokola? Děkuji za každou radu

Jsou zobrazeny jen nové odpovědi. Zobrazit všechny
Předmět Autor Datum
Máš tam cyklus, že skript proběhne 20x. Tak vyhoď ten řádek "for" a na konci uzavírací složenou závo…
host 25.09.2013 20:42
host
Odstranil jsem ten řádek a funguje to skvěle. Můžu se ještě zeptat na jednu věc? Dělám se s tím už n…
Dáda456 25.09.2013 20:59
Dáda456
Takto? function Update() { if (Input.GetKey(KeyCode.X)) { audio.clip = AudioFile; audio.Play(); } }…
Flash_Gordon 25.09.2013 21:18
Flash_Gordon
Já ale potřebuji pouštět klávesou X toto: var texture1 : Texture2D; var texture2 : Texture2D; var t…
Dáda456 25.09.2013 21:21
Dáda456
? function Update() { if (Input.GetKey(KeyCode.X)) { var texture1 : Texture2D; var texture2 : Text…
Flash_Gordon 25.09.2013 21:29
Flash_Gordon
Napíše to: Script error: Update() can not be a coroutine.
Dáda456 25.09.2013 21:36
Dáda456
No. Já to píšu z hlavy, nemám překladač pro kontrolu. Co toto? function Update() { if (Input.GetK… nový
Flash_Gordon 25.09.2013 21:44
Flash_Gordon
Dík jsi borec. Šlape to skvěle. nový
Dáda456 25.09.2013 22:04
Dáda456
To jsem rád, protože už jdu spát a nemuselo by se to dořešit. poslední
Flash_Gordon 25.09.2013 22:06
Flash_Gordon

Odstranil jsem ten řádek a funguje to skvěle. Můžu se ještě zeptat na jednu věc? Dělám se s tím už několik dní a nevím jak dál.
Mám script který spouští zvuk po stisknutí na klávesu X:

var AudioFile : AudioClip;

function Update() {
if (Input.GetKeyDown ("x"))
{
    audio.clip = AudioFile;
    audio.Play();
}
}

Chci aby se tento kód taky spustil stiskem X. Jak to mám popuravit? Když tam vložím if (Input.GetKeyDown ("x")) , tak to nefunguje. Toto chci spouštět klávesou X:

var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;

function Start(){
changeTexture();
}
function Update () {
}
function changeTexture () {


var i= 1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture2;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture3;



}

Děkuji za každou radu

Já ale potřebuji pouštět klávesou X toto:

var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;

function Start(){
changeTexture();
}
function Update () {
}
function changeTexture () {


var i= 1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture2;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture3;



}

Tamten kód je jako příklad.

?

 function Update() {
if (Input.GetKey(KeyCode.X))
{
   var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture2;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture3;

}
}


No. Já to píšu z hlavy, nemám překladač pro kontrolu.

Co toto?

 function Update() {
if (Input.GetKey(KeyCode.X))
{
RenderSometing();
}
}


function RenderSometing() {


   var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture1;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture2;

yield WaitForSeconds(1);
renderer.material.mainTexture = texture3;

}


Zpět do poradny Odpovědět na původní otázku Nahoru