UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Sprite.texture
# [Sprite](https://docs.unity3d.com/cn/2019.4/ScriptReference/Sprite.html).texture public [Texture2D](https://docs.unity3d.com/cn/2019.4/ScriptReference/Texture2D.html) **texture** ; ## 描述 获取对使用的纹理的引用。如果已打包,则指向图集;如果未打包,则指向源精灵。 仅返回精灵当前使用的纹理。不能使用该属性更改纹理。 ``` //Attach this script to a Sprite GameObject. Make sure it has a SpriteRenderer component (should have by default) //Next, attach a second Sprite in the Inspector window of your first Sprite GameObject using UnityEngine; public class Example : MonoBehaviour { SpriteRenderer m_SpriteRenderer; public Sprite m_Sprite; void Start() { //Fetch the SpriteRenderer of the Sprite m_SpriteRenderer = GetComponent<SpriteRenderer>(); //Output the current Texture of the Sprite (this returns the source Sprite if the Texture isn't packed) Debug.Log("Texture 1 : " + m_SpriteRenderer.sprite.texture); } void Update() { //Press Space key to change the Sprite to the Sprite you attach in the Inspector if (Input.GetKeyDown(KeyCode.Space)) { //Change the Sprite m_SpriteRenderer.sprite = m_Sprite; //Output the Texture of the new Sprite (this returns the source Sprite if the Texture isn't packed) Debug.Log("Texture 2 : " + m_SpriteRenderer.sprite.texture); } } } ```
da
2022年6月21日 11:23
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码