Unity- UI,改变图像的色彩,使之调整,占用整个屏幕
问题描述:
我有一个预制,我导入与Unity- UI,改变图像的色彩,使之调整,占用整个屏幕
GameObject imagePrefab = Resources.Load("demonSkull") as GameObject;
image = GameObject.Instantiate(imagePrefab, imagePrefab.transform.position, imagePrefab.transform.rotation) as GameObject;
image.transform.SetParent(GameObject.Find("BattleCanvas").transform, false);
它出现在屏幕就好上。
但是,后来我尝试使用其颜色设置:
GameObject.Find("Foo").GetComponent<Image>().color = new Color32(0, 0, 0, 0);
出于某种奇怪的原因,它不会改变颜色。相反,图像展开占据了整个屏幕。
Unity不会引发错误。
任何想法是什么造成这种情况?
答
您需要更改material.color
通用:
gameObject.GetComponent().material.color = Color.green;
您正在使图像完全透明。也许背后有另一个很大的图像? – JeanLuc