forked from UnityCommunity/UnityLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexturePixels2Quads.cs
More file actions
28 lines (26 loc) · 838 Bytes
/
Copy pathTexturePixels2Quads.cs
File metadata and controls
28 lines (26 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using UnityEngine;
using System.Collections;
// Usage:
// - assign texture (that has [x] read/write enabled in inspector
// - assign Quad mesh (prefab) to planePrefab. You can assign Unlit/Color material to the quad prefab first.
namespace UnityLibrary
{
public class TexturePixels2Quads : MonoBehaviour
{
public Texture2D tex;
public Renderer planePrefab;
void Start()
{
for (int x = 0; x < tex.width; x++)
{
for (int y = 0; y < tex.height; y++)
{
var c = tex.GetPixel(x, y);
var pos = new Vector3(x, y, 0);
var plane = Instantiate(planePrefab, pos, Quaternion.identity) as Renderer;
plane.material.color = c;
}
}
}
}
}