【发布时间】:2016-09-01 20:14:30
【问题描述】:
我有这个脚本:
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++];
}
效果很好,它的作用是在显示所有图像后,它会更改 OnClick 的图像和对象,它会循环播放。但是,我无法在场景窗口中或通过脚本手动缩放图像。有没有更简单的方法来更改我的脚本,以便能够在我的场景窗口中手动缩放我的图像。 (我宁愿在我的场景窗口中缩放我的图像,而不是通过脚本,因为我会发现它更容易)请谢谢你:)
二次编辑 这就是我的脚本现在的样子:
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++];
}
谢谢你:)
【问题讨论】: