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

10 篇文章 0 订阅

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. }  
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值