Skip to content

Commit c579bf5

Browse files
committed
script to display webcam texture into a gameobject
1 parent 4fd9646 commit c579bf5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
// usage: attach this script to any gameobject in which you want to render the webcam display
6+
// create a material, use Unlit/Texture as a shader and place it to the gameobject's material placeholder in the mesh renderer component
7+
8+
namespace UnityLibrary
9+
{
10+
public class WebCamDisplay : MonoBehaviour
11+
{
12+
void Start()
13+
{
14+
WebCamTexture webCam = new WebCamTexture();
15+
webCam.deviceName = WebCamTexture.devices[0].name;
16+
this.GetComponent<MeshRenderer>().material.mainTexture = webCam;
17+
webCam.Play();
18+
}
19+
}
20+
}
21+

0 commit comments

Comments
 (0)