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;