Is possible to attach the script to a UI Image, not to a plane? To get the corrent screen resolution of any device…
using UnityEngine;
using System.Collections;
public class qqqq : MonoBehaviour {
WebCamTexture back;
void Start (){
back = new WebCamTexture ();
GetComponent().material.mainTexture = back;
back.Play ();
}
void Update ()
{
}
}
This specific code - no. But with only one small change, it will work.
NB! You should use Raw Image instead. It is mainly the same as Image, but just using texture instead of sprite. So, I believe it will work with it.
GetComponent<RawImage>().texture = back;
Ok i put an UI Raw image, them add the script to it. But nothing happend.
Works perfectly for me:
IEnumerator Start() {
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam)) {
WebCamTexture web = new WebCamTexture ();
GetComponent<RawImage> ().texture = web;
web.Play ();
}
}
i put the script, here the message.
The type or namespace name `RawImage’ could not be found. Are you missing a using directive or an assembly reference?
using UnityEngine;
using System.Collections;
public class qqqq : MonoBehaviour {
IEnumerator Start ()
{
yield return Application.RequestUserAuthorization (UserAuthorization.WebCam);
if (Application.HasUserAuthorization (UserAuthorization.WebCam)) {
WebCamTexture web = new WebCamTexture ();
GetComponent ().texture = web;
web.Play ();
}
}
}
You need to import a namespace for UIs.
Insert this line at the very beginning:
using UnityEngine.UI;
Is it possible, to put a 3D sphere, on the front of the RawImage?