Unity 3d 2017.2.1相机输入看起来在iPad中放大

时间:2018-01-13 09:02:24

标签: ipad unity3d

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFeed : MonoBehaviour {

// Use this for initialization
public Renderer rend;

void Start () {


    WebCamDevice[] devices = WebCamTexture.devices;

    // for debugging purposes, prints available devices to the console
    for(int i = 0; i < devices.Length; i++)
    {
        print("Webcam available: " + devices[i].name);
    }

    Renderer rend = this.GetComponentInChildren<Renderer>();

    // assuming the first available WebCam is desired
    WebCamTexture tex = new WebCamTexture(devices[0].name);
    rend.material.mainTexture = tex;
    //rend.material.SetTextureScale("tex", new Vector2(1.2f, 1.2f));
    tex.Play();

}

// Update is called once per frame
void Update () {

}
}

我使用上面的代码在平面上渲染摄像头。代码工作正常但我在部署到iPad时看到缩放的Feed(大约1.2倍)。我怎样才能得到正常的饲料。或者如何缩小相机输入

1 个答案:

答案 0 :(得分:0)

根据https://answers.unity.com/questions/1421387/webcamtexture-zoomed-in-on-ipad-pro.html,如果您插入此代码,则应正确缩放:

rend.material.SetTextureScale("_Texture", new Vector2(1f, 1f))

此外,似乎你正在尝试这样的事情,但你的矢量关闭(0.2f)虽然你已经注释掉了那条线。您可以进一步缩小比例,但如果相机无法支持缩小,可能会使图像变得更小:)。