屏幕擦除:
導(dǎo)入圖片师崎,將texture type改為Advanced膀跌,read/write勾上号俐。
為一個(gè)空物體添加界面紋理GUITexture
防止污染原始圖片皆怕,new一個(gè)texture2d來做擦除
關(guān)鍵代碼:
public Texture2D text;
private Texture2D copyText;
copyText = new Texture2D(text.width, text.height);
copyText.SetPixels(text.GetPixels());//提取text圖片的顏色娃殖,賦給copyText
copyText.Apply();
guiTexture.texture = copyText;
Texture2D的一個(gè)函數(shù):
float a = Input.mousePosition.x / screenX;
float b = Input.mousePosition.y / screenY;
int x = (int)(a * copyText.width);
int y = (int)(b * copyText.height);
copyText.SetPixel(x , y , new Color(0, 0, 0, 0));//設(shè)置坐標(biāo)(x值戳,y)處的像素顏色
copyText.Apply();
guiTexture.texture = copyText;
Texture2d還有一個(gè)讀取屏幕像素的函數(shù),就是截屏功能炉爆,在網(wǎng)上找到的一篇文章unity的三種截屏方式
http://blog.csdn.net/anyuanlzh/article/details/17008909
現(xiàn)在用的unity版本會(huì)報(bào)錯(cuò)堕虹,需要把截屏函數(shù)寫成協(xié)程,并在截屏前加上yield return new WaitForEndOfFrame();