实现效果如下:
功能:
1 打开摄像头,摄像头画面作为软件的背景
2 3d物体放在摄像头画面之上
具体实现如下:
具体代码实现如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class cam : MonoBehaviour {
WebCamTexture nn;
public RawImage tt;
// Use this for initialization
void Start () {
StartCoroutine("startCam");
}
public IEnumerator startCam()
{
int maxl = Screen.width;
if (Screen.height > Screen.width)
{
maxl = Screen.height;
}
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[] devices = WebCamTexture.devices;
string devicename = devices[0].name;
nn= new WebCamTexture(devicename, maxl, maxl, 12);
nn.wrapMode = TextureWrapMode.Repeat;
tt.texture = nn;
nn.Play();
}
}
// Update is called once per frame
void Update () {
}
}
FR:海涛高软(hunk Xu)