Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by saiy2k · Feb 06, 2014 at 06:15 AM · camerawebcamtexturefront

Cant access Front (Device) Camera

I am accessing the device camera with the following lines of code:

 for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
     if (WebCamTexture.devices[cameraIndex].isFrontFacing == true) {
         webCameraTexture    =    new WebCamTexture(cameraIndex, Screen.width, Screen.height);
     }
 }
 cameraFrame.renderer.material.mainTexture = webCameraTexture;
 webCameraTexture.Play();

But I couldn't access the front camera in both iOS and Android by checking for isFrontFacing flag. Logging the WebCamTexture.devices array returns 2 devices one with isFrontFacing = true and other with isFrontFacing = false. But the new WebCamTexture seems to be linked to the back camera in both the cases.

I am using Unity 4.3.0f4.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by flamy · Feb 06, 2014 at 06:23 AM

you are actually creating a webcam texture when the device of certain index is front facing, which is nothing but same as creating a webcamtexture new WebCamTexture(cameraIndex, Screen.width, Screen.height); this line.

Instead you have to create the webcamtexture and set the target device to listen to inside tht for loop. the below is the sample that might work . I havnt tested it in device though. But i am positive it should work

  WebCamDevice[] devices = WebCamTexture.devices;
  
  foreach(WebcamDevice cam in devices)
  {
     if(cam.isFrontFacing )
     {    
         webCameraTexture  =    new WebCamTexture(cameraIndex, Screen.width, Screen.height);
         webCameraTexture.deviceName  = cam.name;
         webCameraTexture.Play();
     }
  }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Elliot-Hayward · Aug 17, 2015 at 11:19 PM 0
Share

Unless the API has changed since this question was asked, I believe the issue was actually that new WebCamTexture(cameraIndex, Screen.width, Screen.height); resolves to the constructor WebCamTexture(int requestedWidth, int requestedHeight, int requestedFPS). So, the cameraIndex value was actually being passed to requestedWidth, and so on. If a device name was passed as the first parameter, the rest of the code posted in the original question would have worked fine.

avatar image elenzil · Oct 03, 2016 at 07:09 PM 0
Share

this seems like the right idea, but the code is a little off, because cameraIndex is never used. also there's no fallback case. here's what i'm using, tested on iPhone 6 / iOS 10.

     webCamTexture = null;
     WebCamDevice[] wdcs = WebCamTexture.devices;
     for (int n = 0; n < wdcs.Length; ++n) {
       if (wdcs[n].isFrontFacing) {
         webCamTexture = new WebCamTexture(wdcs[n].name);
       }
     }
 
     if (webCamTexture == null) {
       webCamTexture = new WebCamTexture();
     }
 

i set the width & height later using webCamTexture.requestedWidth and so on, ins$$anonymous$$d of passing them in the constructor.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Switching between front/back device cameras and saving screenshot to photo album 0 Answers

WebCamTexture resolution and cropping problem on Android 0 Answers

How to use device camera to click picture then store it in resources folder in runtime? 0 Answers

Projection mobile camera on a texture, at the same time using it as AR camera. Is it possible? 0 Answers

Access iOS Front Camera in Photo Mode - Not Video - a la Camera App 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges