悉野小楼

导航

Unity Resources.Load

图片路径必须是Assets\Resources目录下面的, 并且不能带扩展名
//E:\Assets\Resources\img\abc.jpg
string filePath = "img/abc";
var texture = Resources.Load<Texture2D>(filePath);
GameObject obj = new GameObject("newname", typeof(SpriteRenderer));
SpriteRenderer render = obj.GetComponent<SpriteRenderer>();
var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); render.sprite = sprite;

  

posted on 2023-04-21 17:47  悉野  阅读(28)  评论(0编辑  收藏  举报