Problem is not reproducible or outdated
Show device camera preview (Android & iOS)
Hi, I'm new to Unity3D and I'm trying to create a simple example of how to use device camera. I did a little sample project, but can't figure it out what's the problem,because if I run the project on Android it doesn't show camera preview. Here is the script and MainCamera and Place's configurations:
![#pragma strict
function Start () {
Debug.Log("Start");
var devices: WebCamDevice[] = WebCamTexture.devices;
for (var i: int = 0; i < devices.Length; i++)
Debug.Log(devices[i].name);
var deviceCamera: GameObject = GameObject.FindWithTag("Player");
var webcamTexture: WebCamTexture = new WebCamTexture();
deviceCamera.GetComponent.<Renderer>().material.mainTexture = webcamTexture;
webcamTexture.Play();
}
function Update () {
Debug.Log("Update");
}][1]
[1]: /storage/temp/77143-screen-shot-2016-08-29-at-125356-pm.png
Any kind of help and suggestions are welcomed!
Thanks in advance!
Answer by macma · Mar 12, 2017 at 07:33 PM
I used RawImage as live window and it worked
public class LiveShowWindow : MonoBehaviour {
public RawImage rawimage;
void Start() {
WebCamTexture webcamTexture = new WebCamTexture(WebCamTexture.devices[WebCamTexture.devices.Length-1].name);
rawimage.texture = webcamTexture;
rawimage.material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}
Follow this Question
Related Questions
What's wrong with my script? 2 Answers
Camera Script remove a part. 0 Answers
How do I make a enter and exit car script? 0 Answers
camera script problems and can't see the selected object 0 Answers
speed = transform.rotation * speed; explanation please? 1 Answer