Can I take a photo in Unity using the device's camera?

前端 未结 7 798
春和景丽
春和景丽 2020-12-06 00:18

I\'m entirely unfamiliar with Unity3D\'s more complex feature set and am curious if it has the capability to take a picture and then manipulate it. Specifically my desire is

7条回答
  •  情书的邮戳
    2020-12-06 00:52

    For those trying to get the camera to render live feed, here's how I managed to pull it off. First, I edited Bart's answer so the texture would be assigned on Update rather than just on Start:

    void Start()
    {
        webCamTexture = new WebCamTexture();
        webCamTexture.Play();
    }
    
    void Update()
    {
        GetComponent().texture = webCamTexture;
    }
    

    Then I attached the script to a GameObject with a RawImage component. You can easily create one by Right Click -> UI -> RawImage in the Hierarchy in the Unity Editor (this requires Unity 4.6 and above). Running it should show a live feed of the camera in your view. As of this writing, Unity 5 supports the use of webcams in the free personal edition of Unity 5.

    I hope this helps anyone looking for a good way to capture live camera feed in Unity.

提交回复
热议问题