Find方法!
1.通过GameObject的名字寻找
//this method is slow, so avoid using this in the Update/FixedUpdate method
public static Object Find (string name, System.Type type)
{
Object[] objs = Resources.FindObjectsOfTypeAll (type);
foreach (Object obj in objs) {
if (obj.name == name) {
return obj;
}
}
return null;
}
参数:name 是GameObject的名字
参数:type 是GameObject的类型
例子:
UIPanel LevelOverPanel = (UIPanel)Utility.Find(Consts.PanelName_LevelOver, typeof(UIPanel));
if (!LevelOverPanel)
{
return;
}
NGUITools.SetActiveSelf (LevelOverPanel.gameObject, true);
2.通过设置Tag查找
UISprite SpriteSweet = GameObject.FindWithTag("Sprite-Sweet").GetComponent<UISprite>() as UISprite;
SpriteSweet.spriteName = "image18";
GameObject.FindWithTag("Door").GetComponent<DoorScript>().ShowPanel_LevelOver();

浙公网安备 33010602011771号