using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public Texture2D t;
[Range(0, 1)]
public float intensity = 0.8f;
public Color drawColor = new Color32(240, 190, 170, 255);
public Color defaultColor = new Color32(0, 0, 0, 0);
Texture2D tt;
void Start () {
transform.localScale = new Vector3 ((float)t.width/(float)t.height, 1);
InvokeRepeating ("MyUpdate", 0, 1);
}
void MyUpdate () {
if(tt != null){
Destroy(tt);
}
tt = new Texture2D (t.width, t.height);
for(int y = 1; y < t.height-1; y++){
for(int x = 1; x < t.width-1; x++){
tt.SetPixel(x, y, t.GetPixel(x, y).grayscale < intensity ? defaultColor : drawColor);
}
}
tt.Apply ();
renderer.material.mainTexture = tt;
}
}
留言列表