How to create sprite at run time?

I found the method Sprite.Create(),but it needed a rect to point out the sprite in a texture,but it’s hard for me to provide that.Since i have made up the sprite in the sprite_editor,how can i just create a sprite from that?Please tell me,thank you!

All you need to do is create a game object and add a SpriteRenderer component, then set its image:

using UnityEngine;

public class MakeSprite : MonoBehaviour
	public Sprite sprite;

	void Start()
		GameObject go = new GameObject("New Sprite");
		SpriteRenderer renderer = go.AddComponent<SpriteRenderer>();
		renderer.sprite = sprite;

To test this script: Attach this to some object, drag the sprite texture to the sprite variable in the inspector, and ensure the texture type is set to “Sprite (2D and UI)”. Extract the code and adapt for your own use :slight_smile: