Unity 打开摄像头

打开摄像头,给项目一个纯透明的背景会不会很酷呢 

    void Start()
    {
        instance = this;

        OpenCamera();
    }

    public void OpenCamera()
    {
        StartCoroutine("StartCamera");
    }
    public IEnumerator StartCamera() {

        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);//申请摄像头权限

        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {
            WebCamDevice[] devices = WebCamTexture.devices;
            string devicsName = devices[0].name;
            WebCamTexture tex = new WebCamTexture(devicsName, Screen.width, Screen.height, 60);
            tex.wrapMode = TextureWrapMode.Repeat;
            GetComponent<RawImage>().texture = tex;
            tex.Play();
        }
    }

这个脚本就挂在原生精灵上,然后我们打个安卓包看效果吧 

背景变成纯透明的之后,好像也别有一番风味 

 

猜你喜欢

转载自blog.csdn.net/Liu_ChangC/article/details/120542988