当前位置 博文首页 > unity工具人的博客:Unity获取屏幕指定坐标的像素颜色

    unity工具人的博客:Unity获取屏幕指定坐标的像素颜色

    作者:[db:作者] 时间:2021-07-20 09:32

    IEnumerator CaptureScreenshot()
        {
            //只在每一帧渲染完成后才读取屏幕信息
            yield return new WaitForEndOfFrame();
    
            Texture2D m_texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
            // 读取Rect范围内的像素并存入纹理中
            m_texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
            // 实际应用纹理
            m_texture.Apply();
    
            Color color = m_texture.GetPixel((int)Input.mousePosition.x, (int)Input.mousePosition.y);
    
    }
    
    cs