unity3d 更换sprite renderer中sprite的图片
所更换图片尺寸与原图片相同
SpriteRenderer spr = gameObject.GetComponent<SpriteRenderer>();
Texture2D texture2d = (Texture2D)Resources.Load("herominired");//更换为红色主题英雄角色图片
Sprite sp = Sprite.Create(texture2d,spr.sprite.textureRect,new Vector2(0.5f,0.5f));//注意居中显示采用0.5f值
spr.sprite = sp;