added course prototype, image switch not working yet
This commit is contained in:
50
Assets/Scripts/Webcam.cs
Normal file
50
Assets/Scripts/Webcam.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Webcam : MonoBehaviour
|
||||
{
|
||||
int camdex = 0;
|
||||
WebCamTexture tex;
|
||||
|
||||
public RawImage display;
|
||||
public Button nextSignButton;
|
||||
|
||||
void Awake(){
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
|
||||
public void SwapCam(){
|
||||
if(WebCamTexture.devices.Length > 0){
|
||||
// Stop the old camera
|
||||
display.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
// Find the new camera
|
||||
camdex += 1;
|
||||
camdex %= WebCamTexture.devices.Length;
|
||||
|
||||
// Start the new camera
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
tex = new WebCamTexture(device.name);
|
||||
display.texture = tex;
|
||||
|
||||
tex.Play();
|
||||
}
|
||||
}
|
||||
// Scene changing is implemented here to avoid problems with webcam
|
||||
public void loadScene(string sceneName) {
|
||||
display.texture = null;
|
||||
tex.Stop();
|
||||
tex = null;
|
||||
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user