public Texture texture ;

描述

RawImage 的纹理。

使用此设置可更改或返回 RawImage 显示的纹理。RawImage 可以显示任何纹理,而 Image 组件只能显示 Sprite 纹理。

注意:谨记,使用 RawImage 时,将使用每个存在的 RawImage 创建一个额外的绘制调用,因此最好只将其用于背景或临时可见的图形。

//Create a new RawImage by going to Create>UI>Raw Image in the hierarchy.
//Attach this script to the RawImage GameObject.

using UnityEngine; using UnityEngine.UI;

public class RawImageTexture : MonoBehaviour { RawImage m_RawImage; //Select a Texture in the Inspector to change to public Texture m_Texture;

void Start() { //Fetch the RawImage component from the GameObject m_RawImage = GetComponent<RawImage>(); //Change the Texture to be the one you define in the Inspector m_RawImage.texture = m_Texture; } }