找回密码
 立即注册
查看: 688|回复: 3

[常见问题] renderer问题

[复制链接]
发表于 2020-7-27 18:51 | 显示全部楼层 |阅读模式
gameObject.renderer.material.color=Color.red;
为什么会报错,Unity5.0版本,请教大佬...
发表于 2020-7-27 18:58 | 显示全部楼层
gameObject.GetComponent<Renderer>().material.color = Color.red;
 楼主| 发表于 2020-7-28 14:51 | 显示全部楼层
巨蟹座 发表于 2020-7-27 18:58
gameObject.GetComponent().material.color = Color.red;

应该是gameObject.GetComponent.<Renderer>().material.color = Color.red;吧,改了之后虽然没有error了,但运行时会弹出NullReferenceException: Object reference not set to an instance of an object,然后物体的颜色还是没变...
发表于 2020-7-28 19:51 | 显示全部楼层
CSTG 发表于 2020-7-28 14:51
应该是gameObject.GetComponent.().material.color = Color.red;吧,改了之后虽然没有error了,但运行时 ...

确定一下这个gameObject 有问题吗?是不是空了,你试试另外建立另外一个对象试试
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 01:47 , Processed in 0.107493 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表