unity3d - 如何:获取对 UI 图像的引用
问题描述
与我之前提出的问题类似,我现在正在学习如何TestImage
在脚本中获取我的图像的参考。
到目前为止,我已经尝试过:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class imageGrab : MonoBehaviour
{
[Space] public RawImage testImage;
Texture2D profileTexture;
// Start is called before the first frame update
void Start()
{
profileTexture = new Texture2D(2, 2);
}
void Awake()
{
PlayPortalProfileClient.Instance.GetMyProfilePicture((error, data) =>
{
if (error != null)
{
ErrorLogging("Error requesting my profile picture.", error);
}
else
{
Debug.Log("Got my profile picture successfully.");
profileTexture.LoadImage(data);
testImage.texture = profileTexture;
}
});
}
// Update is called once per frame
void Update()
{
}
}
但是遇到这个错误,Assets/imageGrab.cs(8,24): error CS0246: The type or namespace name 'RawImage' could not be found (are you missing a using directive or an assembly reference?)
我可以做些什么来正确获得参考?有没有像引用文本元素一样简单的东西?谢谢!
解决方案
把它放在最上面:
using UnityEngine.UI
推荐阅读
- python - Python 2.7 XML RPC:如何获取服务器上的传入请求?
- javascript - textureLoader 不适用于法线贴图
- node.js - 节点 AWS SDK v3:Lambda 函数中的“事件”和“上下文”参数的类型?
- azure-ad-b2c - 在 Azure B2C 中获取刷新令牌,Azure AD App 是第三方 IDP
- c# - Entity Framework Core 关系跟踪
- artifactory - Artifactory:以非递归方式下载最新发布的构建的所有根文件
- python - pywinauto 看不到通过 inspect.exe 可见的元素
- javascript - 为什么我的购物车增量计数器不起作用?
- python - Python线性规划——连续夜班调度优化约束
- reactjs - 在 React 组件中测试异步代码(useEffect + fetch)