Unity - A.unity - New Unity Project 14 - PC, Mac & Linux Standalone DX11_2

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;
    }
}






 

arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()