【发布时间】:2019-09-22 10:23:21
【问题描述】:
我正在开发这款游戏,并且图像在 Unity 编辑器的游戏屏幕中显示良好,但是当我构建和运行时,图像是空白的。 统一的游戏视图: !(Game view in unity) the view after building 纹理来源是硬盘。 图像不在项目文件夹中且未构建 有什么建议? 请注意我正在学习统一和 CSharp(新用户)。
按键代码:
public Category category;
public TextMeshProUGUI text;
public RawImage image;
public bool isFilled = false;
public int directoryLineNumber;
public void UpdateButtonData()
{
text.text = category.name;
image.texture = category.GetARandomImage();
//image.Rebuild(0);
isFilled = true;
}
{
public string name;
public string text;
public List<Item> items;
private string _path;
//some code here not related
public Texture2D GetARandomImage()
{
DirectoryInfo dir = new DirectoryInfo(_path);
FileSystemInfo[] images = dir.GetFileSystemInfos();
int i = Random.Range(0, images.Length);
if (images[i].ToString().Contains(".png"))
{
WWW wWW = new WWW(images[i].ToString());
/* Wait !! */
while (!wWW.isDone) { }
return wWW.texture;
}
else return GetARandomImage();
}
【问题讨论】:
-
这是一个常见问题,可能来自许多地方。尝试从 Build 中删除所有场景并将其重新添加。
-
现在我尝试: - 删除并重新附加场景 - 卸载并重新安装 Unity - 从编辑器添加纹理(它有效,但该方法不适合游戏) - 我用过一台不同的电脑,它是一样的,请任何我很高兴听到的建议,即使它只是重新启动我的电脑 Lol。
-
如果使用编辑器中的纹理有效,为什么不使用它呢?我认为这是由于性能问题。如果是这样,我已经写信给另一个用户how to proceed to get an app faster
标签: c# image unity3d game-engine