Unity3D调用摄像头,画面为翻转的问题

http://blog.csdn.net/a117653909/article/details/16119907

Unity3D中新建一个工程,加一个Plane,新建一个C# 脚本,调用摄像头,不过显示的图片居然是翻转的,也就是头朝地下。调了半天,原来是Plane反掉了,Plane的Rotation X值改为90,Y改为180就可以了。


晒下代码:

[html] view plain copy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class C : MonoBehaviour   
  5. {  
  6.     WebCamTexture webcamTexture;  
  7.     // Use this for initialization  
  8.     void Start ()   
  9.     {  
  10.         WebCamDevice[] devices = WebCamTexture.devices;  
  11.         if (devices.Length > 0)  
  12.         {  
  13.             webcamTexture = new WebCamTexture(devices[0].name, 320, 240, 25);  
  14.             renderer.material.mainTexture = webcamTexture;  
  15.             webcamTexture.Play();  
  16.         }  
  17.     }  
  18.       
  19.     // Update is called once per frame  
  20.     void Update ()   
  21.     {  
  22.       
  23.     }  
  24. }  

或者:

[csharp] view plain copy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class B : MonoBehaviour   
  5. {  
  6.     public string deviceName;    
  7.     WebCamTexture tex;  
  8.       
  9.     IEnumerator Start()  
  10.     {  
  11.         //获取授权    
  12.         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);    
  13.         if (Application.HasUserAuthorization(UserAuthorization.WebCam))    
  14.         {    
  15.             WebCamDevice[] devices = WebCamTexture.devices;    
  16.             deviceName = devices[0].name;    
  17.             tex = new WebCamTexture(deviceName, 480, 320, 25);    
  18.             renderer.material.mainTexture = tex;    
  19.             tex.Play();    
  20.         }  
  21.     }  
  22. }  

posted @ 2016-08-03 10:51  00000000O  阅读(854)  评论(0编辑  收藏  举报