Unity WebGL build Webcam texture not working - unity3d

I have basic webgl app with Unity3D 2017 where im using webcam texture to display webcam feed on the screen. Here is the code im using to request webcam permission:
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
Debug.Log("webcam found");
startWebCam ();
}
else
{
Debug.Log("webcam not found");
}
And here is the code to render webcam feed on a plane that users see.
void startWebCam() {
WebCamDevice device = WebCamTexture.devices[0];
cam_texture = new WebCamTexture (device.name);
camera_renderer.material.mainTexture = cam_texture;
cam_texture.Play ();
}
It works fine in editor but does not work when i export a webgl build. It does ask for permission to use webcam and then the green light beside my laptop camera turns on but all i can see is black screen. However, the was one time when I think i refreshed twice or something, the webcam feed appeared. I have not been able to reproduce it after that.
Would appreciate any help here. Thanks.

Got the issue resolved. The problem was that autoplay is forbidden on Webgl apps (at least on chrome). So all i had to do is ask user to tap on screen before starting webcam. Fixed.

Related

Unity Video Player, the video cannot be played properly

I am developing a game for android and ios via Unity. I have to play a video in a scene in the game and I use the video player component for this. I get the video link on local using xampp. And the video I'm trying to play is in mp4 format. But when I start the game, the video cannot be played properly. I am not getting an error, but video looks like the picture I send. I don't know what I'm doing wrong, can you help me? I also share the code I used and related pictures with you.
public VideoPlayer videoplayer;
public string videoUrl="urlgir";
void Start() {
videoplayer.url = videoUrl;
videoplayer.audioOutputMode=VideoAudioOutputMode.AudioSource;
videoplayer.EnableAudioTrack (0, true);
videoplayer.Prepare (); }
I think I found something. I uploaded the video I mentioned to unity again. I got a warning after uploading the video.
VFR warning: 1111 video frames have a different duration than expected 0.0333333s, ranging from 0s to 1.2771s.D:/Program Files/Unity/xxx/Assets/Scenes/hp.mp4 (30FPS) may have variable frame rate (VFR), which is not supported. This may lead to incorrect timing in transcoded clip.
I think the video has unsupported variable frame rate. So I can't run the video as clib or url. Well, does anyone know of this warning? What should be needed?

Unity WebGl does not free webcam when stopped

Good time of day, I want to make an image using the webcam. When I take image, call method texture.Stop(); but the camera is not freed anyway (white light is on). All work right in other platforms.
How to shut down a camera in WebGL?
The code method it taked image.
private void OnCaptureTake()
{
if (_captureImage.texture != null)
{
((WebCamTexture)_captureImage.texture).Stop();
OnTakeTexture.SafeInvoke(_captureImage);
_isOnClick = false;
_takeCaptureButton.SetActive(false);
_captureImage.gameObject.SetActive(false);
}
}
/*****************************************/
UPDATE
Link to the bug report on the unity bug report.

Unity3d EasyAR Target loads at the start of the camera before find the trarget

I am tring to build an AR android app with unity3d last version and EASYAR SDK.
I have create the target and i am able to load my image or video at it's chile object but the child objct (cube or plane) load imediately when th camera opens.
i am looking some help on how i can apear the image or start the video when the camera find the target and not when the app starts.
thnns a lot in advanced guys for the help!!!
You can simply disable them in the beginning and modify the OnTargetFound event of the ImageTargetBehaviour script to enable them. Something like this:
public GameObject myARObject;
void OnTargetFound(TargetAbstractBehaviour behaviour)
{
Debug.Log("Found: " + Target.Id);
myARObject.SetActive (true);
}
Hope this helps.

Unity3D - Unity Ads lower down my Android FPS

So I decided to finally put Unity Ads on my Android game. I tried to build it on Windows platform and found no problem (FPS is fine)
But when I rebuilt it for Android, my FPS scaled down to 30+, what just happened?
I didn't put anything but integrating the Unity Ads so this time I just comment out the Ads that initializes the ads.
void InitializeAds(){
StartCoroutine(ShowAdWhenReady());
}
IEnumerator ShowAdWhenReady(){
while(!Advertisement.IsReady()){
yield return null;
}
Advertisement.Show();
}
In hopes that the FPS will go back to normal. But heck when I recompiled the APK and installed it on my phone the FPS still around 30+ FPS :/
Any help regarding this? I'm certain my game has good frame rate before I put the ads so I know there must be some kind of bugs on the plugin.
By the way, I invoked the InitializedAds on the Start method.
Thanks!
UPDATE:
I installed Unity Remote from Google Play to see if it's also going to have same low FPS but its NORMAL. So I recompiled the current Unity project, installed on my phone, FPS still SUCKS. This is so straaange T.T
Please try this for making FPS higher in your game,
Application.targetFrameRate = 60;
I guess, your problem will solved using this line.

Cannot Change to a specific scene in Unity after building it to mobile device

Currently I'm using Application.load() to change scenes and it works perfectly in Unity. When I built it to a mobile platform and tested it, only in that one scene I can't change to a specific scene.
For example, gameplayScene, levelSelectionScene, mainMenu. I'm able to change scene from mainMenu to levelSelectionScene and then to gameplayScene. For unknown reason, I'm unable to go back to levelSelectionScene from gameplayScene while I can change scene to mainMenu from gameplayScene.
Below is the sample code from button that goes to levelSelectionScene from gameplayScene
private void OnClick ()
{
Debug.Log ("clicked");
if (PlayerPrefs.GetInt("SanguineDifficultyAchieved") == 1)
{
Debug.Log("Entering Difficulty");
m_Owner.SetActive ();
}
else
{
Debug.Log("Exiting");
State.Current = State.NotInGame;
Application.LoadLevel(scene.name);
}
m_Owner.close ();
I don't understand why it works on Unity debugger but then it doesn't work on mobile platforms.
Update 1
I tried to use numbers instead of strings it worked well. But I still don't understand the reason why.
Finally got an answer. It seems that the scenes collided with each other because I use scenes from Asset Bundle and the added scenes from build settings. That is why the when i use Application.Load(int number) works because i only access the scene from build settings.