【发布时间】:2018-12-02 17:38:20
【问题描述】:
void Start () {
foreach (Sprite texture in spriteImages) {
GameObject button = Instantiate (shopButtonPrefab) as GameObject;
button.GetComponentInChildren<Image>().sprite = texture;
button.transform.SetParent (shopButtonContrainer.transform, false);
}
}
我有一个按钮预制件,即一个按钮,带有一个图像组件作为子组件。我不确定为什么我的代码会更改与孩子相反的按钮精灵图像。我改变孩子很重要,我改变它的图像也是一个圆圈,所以我不想丢失按钮已经是矩形默认图像。如何更改子图像,同时将按钮图像保留为默认值?
【问题讨论】: