Convert a Texture2D to Sprite


I would like to convert an array of Texture2D to an array or Sprites.

I tried this method:

Sprite.Create(texture, rect, pivot);

But how to set the exact rect and the exact pivot of a texture?


The rectangle parameter is the source rectangle on the texture. If you want to use the whole texture as the sprite, use new Rect(0, 0, texture.width, texture.height);

I believe the pivot is actually a percentage and not a pixel/unit value. So if you wanted to pivot at the center of the texture you would use new Vector2(0.5f, 0.5f)

Sorry for the pseudo code, away from Unity at the moment.

Hope this helps!

hello, maybe it’s a late reply but my suggestion is :
when you dealing with sprite downloaded and created at Runtime , i recommand to use RawImage better than UIimage because Sprite.Create use more CPU example :

using UnityEngine;
using System.Collections;

// Get the latest webcam shot from outside "Friday's" in Times Square
public class ExampleClass : MonoBehaviour
public RawImgae Rimage;
    public string url = "";

    IEnumerator Start()
        // Start a download of the given URL
        WWW www = new WWW(url);

        // Wait for download to complete
        yield return www;

        // assign texture
        Rimage.texture = www.texture;