Resource.load textur2D

Questions à propos du scripting. Hors Shader, GUI, Audio et Mobile.
royalskunk
Messages : 163
Inscription : 30 Juin 2010 00:53

Re: Resource.load textur2D

Message par royalskunk » 14 Jan 2011 17:43

dernieres question.... :?
Auriez vous des conseils pour optimiser ce code,je trouve que j'ai pas mal de répétitions...

var texture1 : Texture2D;
var texture2 : Texture2D;
var texture3 : Texture2D;
var texture4 : Texture2D;
var texture5 : Texture2D;
var texture6 : Texture2D;
var texture7 : Texture2D;
var texture8 : Texture2D;

function Start () {
deal ();
flop ();
flop2 ();
flop3 ();
}
function deal () {
var carte : GameObject;
carte = GameObject.Find("Player1/carte1");
var textures : Object[] = Resources.LoadAll("Cards", Texture2D);
texture1 = textures[Random.Range(0, textures.Length)];
carte.renderer.material.mainTexture = texture1;
print (texture1.name);

var carte2 : GameObject;
carte2 = GameObject.Find("Player1/carte2");
var textures2 : Object[] = Resources.LoadAll("Cards", Texture2D);
texture2 = textures2[Random.Range(0, textures2.Length)];
if ( texture2==texture1) {
print("egaux");
deal ();
}
else {
carte2.renderer.material.mainTexture = texture2;
print (texture2.name);
}
}
function flop () {
var flop : GameObject;
flop = GameObject.Find("flop/1");
var textures3 : Object[] = Resources.LoadAll("Cards", Texture2D);
texture3 = textures3[Random.Range(0, textures3.Length)];
if (texture3==texture1 ||texture3==texture2) {
print("egaux");
flop ();
}
else {
flop.renderer.material.mainTexture = texture3;
print (texture3.name);
}

}

function flop2 () {
var flop2 : GameObject;
flop2 = GameObject.Find("flop/2");
var textures4 : Object[] = Resources.LoadAll("Cards", Texture2D);
texture4 = textures4[Random.Range(0, textures4.Length)];
if (texture4==texture1 ||texture4==texture2 ||texture4==texture3) {
print("egaux");
flop2 ();
}
else {
flop2.renderer.material.mainTexture = texture4;
print (texture4.name);
}

}

function flop3 () {
var flop3 : GameObject;
flop3 = GameObject.Find("flop/3");
var textures5 : Object[] = Resources.LoadAll("Cards", Texture2D);
texture5 = textures5[Random.Range(0, textures5.Length)];
if (texture5==texture1 ||texture5==texture2 ||texture5==texture3 ||texture5==texture4) {
print("egaux");
flop3 ();
}
else {
flop3.renderer.material.mainTexture = texture5;
print (texture5.name);
}

}

Avatar de l’utilisateur
giyomuSan
Messages : 1799
Inscription : 09 Déc 2009 14:52
Localisation : Japon

Re: Resource.load textur2D

Message par giyomuSan » 15 Jan 2011 11:16

Resources.LoadAll("Cards", Texture2D);

J'imagine que ca charge toujours les meme carte a chaque fois ds le dossier Resources ?
Dans ce cas pas besoin d'aller les charger a chaque fois , fais le 1 fois des le depart, et tu rempli ton tableau avec
ensuite attribut tes cartes.
De la meme maniere tes variable du debut ca sert a rien utilise un tableau

deja ca devrais faire le menage un peu ^^

royalskunk
Messages : 163
Inscription : 30 Juin 2010 00:53

Re: Resource.load textur2D

Message par royalskunk » 15 Jan 2011 16:51

Ok merci pour ces pistes faut vraiment que j'apprenne à utiliser plus ces tableaux.
mais comment remplir mon tableau sont lui dire a chaque fois quel texture va ou. par ex la texture no 1 à 13 va dans la premières colonne....

Avatar de l’utilisateur
Freelax
Messages : 1595
Inscription : 30 Déc 2009 23:02
Localisation : Niort
Contact :

Re: Resource.load textur2D

Message par Freelax » 15 Jan 2011 17:09

le mieux c'est que tu fasse un tableau avec une simple colonne ;)
Image

Répondre

Revenir vers « Scripting »