J'ai ce script:Unity2D: Affichage de l'image dans la fenêtre scène
public Sprite[] Images; //Index starts at one because we are setting the first sprite in Start() method
public int _Index = 1;
public float width;
public float height;
void Start(){
//Set the image to the first one
this.gameObject.GetComponent<SpriteRenderer>().sprite = Images[0];
}
public void onClick(){
//Reset back to 0 so it can loop again if the last sprite has been shown
if (_Index >= Images.Length)
_Index = 0;
//Set the image to array at element index, then increment
this.gameObject.GetComponent<SpriteRenderer>().sprite = Images[_Index++];
}
qui fonctionne parfaitement, ce qu'il fait est qu'il change l'image et l'objet Surclic une fois toutes les images a été montré qu'il boucles. Cependant, je ne peux pas redimensionner mes images manuellement dans ma fenêtre de scène ou à travers un script. Y a-t-il un moyen plus simple de changer mon script pour pouvoir mettre à l'échelle manuellement mes images dans ma fenêtre de scène. S'il vous plaît et merci :)
Second Edition (je préférerais échelle mes images dans la fenêtre de ma scène plutôt que par script, car je trouverais plus facile) C'est ce qui ressemble mon script comme maintenant:
public Sprite[] Images;
//Index starts at one because we are setting the first sprite in Start() method
public int _Index = 1;
public float width;
public float height;
public float lastWidth;
public float lastHeight;
void ResizeMe()
{
this.width = 1.567892f;
this.height = 1.07f;
}
void Update()
{
if(this.width != lastWidth || this.height != lastHeight)
{
ResizeMe (this.width, this.height);
this.lastWidth = width;
this.lastHeight = height;
}
}
void Start(){
//Set the image to the first one
this.gameObject.GetComponent<SpriteRenderer>().sprite = Images[0];
}
public void onClick(){
//Reset back to 0 so it can loop again if the last sprite has been shown
if (_Index >= Images.Length)
_Index = 0;
//Set the image to array at element index, then increment
this.gameObject.GetComponent<SpriteRenderer>().sprite = Images[_Index++];
}
Merci :)
merci pour la réponse mais je reçois cette erreur: erreur CS1525: Symbole inattendu 'this ' . Il renvoie à \t this.lastWidth = width; –
@ Bakausagi-chan Vous devez mettre ';' après 'setSize (this.width, this.height)'. Pour votre information, vous devez vraiment commencer à accepter des réponses s'ils ont résolu votre problème. C'est une façon de dire merci. Vous obtenez tellement d'aide sur SO, mais vous ne semblez pas accepter l'un d'eux, même ceux qui semblent avoir résolu votre problème. – Programmer
Ha, Désolé, j'ai été très récemment essayé –