Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by a_izad · Feb 14, 2015 at 07:37 PM · iphonewebcamtexture

WebCamTexture problem

I am developing an app for iOs and Android devices, I want to use the front camera of the device, I used WebCamTexture for this purpose. When I run the app in Editor, the stream from camera comes perfect, but on iphone or iPad the stream is 90 degrees rotated. I searched the forums and got into this solution:

http://docs.unity3d.com/ScriptReference/WebCamTexture-videoRotationAngle.html

I read somewhere that using the link above must fix your issue, but when I run the code above on iPhone, my whole plane (GameObject which is running the script) dissappears. I searched a lot but did'nt found anything. how can I solve this issue?

my Unity pro version: 4.5.5 xcode version: 6.1 running on iPhone 5S with iOS version: 7.1 also running on iPad with iOS version: 8.0.1 also running on Simulator (iPhone 6 version: 8.1)

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
0

Answer by swappy123 · Jan 24, 2020 at 12:11 PM

I am not sure if my answer will work, but this is finest solution that could help you out for camera rotation angle.

(Below code is not created by me, I have followed tutorial on YouTube to get working camera for my devices and changed some part of code as required by me).

Steps to use:

1) Add RawImage UI gameobject in your scene. (set it's pivot to stretch to fill screen width and height).

2) Add AspectRatioFitter script on this object.

3) Attach following script to any other gameobject you like.

4) Add appropriate component reference to your CameraManager script objects.

 private bool isCamAvailable;
 private WebCamTexture backCam;
 private Texture defaultBackground;

 public RawImage background;
 public AspectRatioFitter fit;

 private void Start()
 {
     StartCoroutine("CheckAuthentication");
 }

 private void Update()
 {
     if (!isCamAvailable)
         return;

     float ratio = (float)backCam.width / (float)backCam.height;
     fit.aspectRatio = ratio;

     float scaleY = backCam.videoVerticallyMirrored ? -1f : 1f;
     background.rectTransform.localScale = new Vector3(1f, scaleY, 1f);

     int orient = -backCam.videoRotationAngle;
     background.rectTransform.localEulerAngles = new Vector3(0, 0, orient);
 }

 IEnumerator CheckAuthentication() {
     yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
     if (Application.HasUserAuthorization(UserAuthorization.WebCam)) {
         defaultBackground = background.texture;
         WebCamDevice[] devices = WebCamTexture.devices;

         if (devices.Length == 0)
         {
             Debug.Log("No camera detected");
             isCamAvailable = false;
         }
         else
         {
             for (int i = 0; i < devices.Length; i++)
             {
                 if (!devices[i].isFrontFacing)
                 {
                     backCam = new WebCamTexture(devices[i].name, Screen.width, Screen.height);
                 }
             }

             if (backCam == null)
             {
                 Debug.Log("No back cam found!!");
                 backCam = new WebCamTexture(devices[0].name, Screen.width, Screen.height);
                 //return;
             }

             backCam.Play();
             background.texture = backCam;

             isCamAvailable = true;
         }
     }
 }

}

vote up if you like my answer. Happy coding..

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

iOS WebCamTexture Displaying Wrong Resolution 1 Answer

Is it Possible to (tap to focus) using WebCamTexture? 1 Answer

Game crashes on reuse of webcam texture in iphone and ipad 1 Answer

iAd in Unity 1.7 1 Answer

How to detect Game Object is touched in Unity iPhone? 1 Answer


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