将图像组件添加到新的游戏对象 [英] Add Image component to new gameobject
本文介绍了将图像组件添加到新的游戏对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个新的游戏对象:
I created a new game object:
GameObject newObject = new GameObject("ObjectName");
newObject.AddComponent<RectTransform>();
newObject.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
我正在寻找一种添加图像(脚本)以达到彩色目的的方法. 我该怎么办?
I'm looking for a way to add an image (script) for color purposes. How can I do it?
推荐答案
与添加RectTransform的方式相同.
The same way you are adding RectTransform.
newObject.AddComponent<Image>();
您还需要添加using UnityEngine.UI
才能找到Image组件.
You also need to add using UnityEngine.UI
to be able to find the Image component.
这篇关于将图像组件添加到新的游戏对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文