Unity创建Image时发生错误

Unity创建Image时发生错误,第1张

如果你用的是Unity内置GUI系统OnGUI()等,GUI脚本挂在任何GameObject下都可以,你可以新建一个空的GameObject然后挂到其上(或其子对象)作为它的部件统一管理

需要在头文件里面定义一下

我圈中的那***哪里,不能没办法获取到image组件

using UnityEngine

using System.Collections

using UnityEngine.UI

using UnityEngine.Sprites

public class OnButton : MonoBehaviour {

private Button button

private Image image

void Start () {

button=this.GetComponent<Button>()

image=this.GetComponent<Image>()

}

private void ButtonDown()

{

button.interactable=false image.overrideSprite=Resources.Load("Textures/TechBlue/background",typeof(Sprite))as Sprite//这里就是修改他的图片

image.color=Color.red

}

}

最后记住,在图片哪里我们需要换一下类型,不然没办法修改他的图片


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11671826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存