在Unity中实例化UI对象并且不在屏幕上显示?

时间:2015-12-30 01:03:36

标签: unity3d unity5

我在Unity(CSharp)中有这样的代码:

public GameObject button;
public GameObject panel;

void Start () {
    button.transform.SetParent (panel.transform);
    Sprite shape = Resources.Load<Sprite>("Logo");
    var img = button.transform.GetComponent("Image") as Image;
    img.sprite = shape;
    img.color = new Color (50, 50, 50, 50);
}

现在,这就是我的场景在Play之前的样子:

The button in the left side is the one i will try to instantiate in my code and "Albumes" is the Panel.

然后,当我按下播放按钮时,我得到了这个:

I can see in the inspector that the sprite was successfuly loaded

有人可以告诉我有关此行为的任何线索吗?

1 个答案:

答案 0 :(得分:0)

嗯,好像你分配精灵的方式不正确。精灵通过UPDATE users SET username=:username ,password=:password WHERE username='term' 分配。你可以试试这个,

Sprite.Create