using UnityEngine;
public class JiePing : MonoBehaviour {
private int ScreenWidth;
//记录屏幕的宽度
private int ScreenHeight;
//记录屏幕的高度
private Texture2D TextureShot;
//储存截图
public Texture2D Textuer1;
public Texture2D Texture2;
private int i = 0;
public GameObject Shpere;
// Use this for initialization
void Start () {
ScreenHeight = Screen.height;
ScreenWidth = Screen.width;
// 标准格式 : Texture2D(int width,int height,TextureFormat format,bool mipmap);
// “int width,int height,” 纹理的宽高
//"TextureFormat format" 纹理的模式 RGB24 RGBA32等模式
//"bool mipmap"mipmap是一种分级纹理 在屏幕中显示大小不同时候给予不同级别的纹理 这里不使用
}
// Update is called once per frame
void Update () {
}
public void ScreenShot() //按钮监听事件
{
TextureShot = new Texture2D(ScreenWidth, ScreenHeight, TextureFormat.RGB24, false);
TextureShot.ReadPixels(new Rect(0, 0, ScreenWidth, ScreenHeight), 0, 0);
TextureShot.Apply();
Shpere.GetComponent<Renderer>().material.mainTexture = TextureShot;
}
}
当按钮按下就会报错,但是运行结果把截图赋给了给定的物体上;
希望大牛能给予指点。