首页 > 代码库 > Unity3d 4.3 通过代码动态更改SpriteRender的Sprite

Unity3d 4.3 通过代码动态更改SpriteRender的Sprite

http://www.unitymanual.com/home.php?mod=space&uid=2452&do=blog&id=420

using UnityEngine;using System.Collections;public class TestSprite : MonoBehaviour {    public Sprite spriteA;    public Texture2D Tex;    // Use this for initialization    void Start () {        Tex = Resources.Load("Enter") as Texture2D;        //Create(源资源,对应sprite的矩形,对应sprite的中心点坐标)        spriteA = Sprite.Create(Tex, new Rect(171, 0, 171, 95), new Vector2(0.5f, 0.5f));        gameObject.GetComponent<SpriteRenderer>().sprite = spriteA;            }        // Update is called once per frame    void Update () {        }}

 

Unity3d 4.3 通过代码动态更改SpriteRender的Sprite