unity 一个UI和模型的需求,要求模型位于两个ui之间

版权声明:转载请注明,谢谢 https://blog.csdn.net/qq_38655924/article/details/83856814

如图所示 后面的ui是摄像机的rawimage代码是:




using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;



[RequireComponent(typeof(RawImage))]  //脚本挂在RawImage  

public class CameraDevice : MonoBehaviour

{

    private List<WebCamTexture> webCamTextures = new List<WebCamTexture>();

    private RawImage image;

    #region Unity Method

    // Called once before Start

    void Awake()

    {

        image = GetComponent<RawImage>();

    }



    // Use this for initialization

    IEnumerator Start()

    {
        //获取授权  
        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {

            WebCamDevice[] devices = WebCamTexture.devices;

            for (int i = 0; i < devices.Length; i++)

            {

                WebCamTexture webCamTexture = new WebCamTexture(devices[i].name, 400, 300, 12);

                webCamTexture.Play();

                webCamTextures.Add(webCamTexture);
                image.texture = webCamTextures[0];  //直接调用了  没有经过按钮调用
            }

        }

    }



    // Update is called once per frame

    void Update()

    {

       


    }



    // OnDestroy is called when the App is killed

    void OnDestroy()

    {



    }

    #endregion



    public void SetDevice(int index)  //按钮调用

    {

        image.texture = webCamTextures[index];

    }

}

猜你喜欢

转载自blog.csdn.net/qq_38655924/article/details/83856814
今日推荐