How to use sections of a texture?

Hello, I am new to Unity and am trying to create a simple puzzle game. I have an image and I want each puzzle piece to have a part of the image.

Say for example that my image is 100x by 100y. I want piece1 to go from (0x-50x,0y-50y), piece2 from (50x-100x,0y-50y), piece 3 (0x-50x,50y-100y), and piece 4 (50x-100x,50y-100y).

Making a lot of small textures and materials for every piece is impractical. I would like to have one image and through a script assign each piece.

So like… (made up code follows)

piece1 = image1(0-50,0-50)

piece2 = image1(50-100,0-50)

…and so on.

I could then have different images for the puzzle and would only need to change the name in the script.

As I understand sprites don’t render lighting so I’d rather use something else, but if that is the only way then so be it.

So how can I accomplish this?

Problem solved!

I had the vertices in the wrong order.

using UnityEngine;
using System.Collections;

public class test2 : MonoBehaviour {

	private Mesh mesh;
	private Vector2[] uvs;
	
	void Start () {

		mesh = this.GetComponent<MeshFilter> ().mesh;
		uvs = mesh.uv;

		uvs[0] = new Vector2(0.0f, 0.0f);
		uvs[1] = new Vector2(1.0f, 1.0f);
		uvs[2] = new Vector2(1.0f, 0.0f);
		uvs[3] = new Vector2(0.0f, 1.0f);

		mesh.uv = uvs;

	}
}

It seems the order for a unity created quad is: bottom left, top right, lower right, top left. This script gives me the full image but by adjusting the float values I can choose any portion I want.

Thank you so much! This is exactly what I wanted.