---
# System prepended metadata

title: PicoCanvasAddCamera.cs

---

# PicoCanvasAddCamera.cs
### 加入此部件到 Canvas 底下
* 出現 `... didnt get the camera.` 表示沒有抓到場景中的主攝影機，
  不過如果此 Canvas 不需要互動沒關係。

```csharp=
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PicoCanvasAddCamera : MonoBehaviour
{
    private Canvas canvas;
    void Start()
    {
        canvas = this.GetComponent<Canvas>();
        canvas.renderMode = RenderMode.WorldSpace;
        if( this.gameObject.GetComponent<Pvr_UICanvas>() == null )
            this.gameObject.AddComponent<Pvr_UICanvas>();
        GetWordlCamera();
    }

    private void GetWordlCamera()
    {
        // 記得 Pvr_UnitySDK 底下的 Head 要給它 MainCamera Tag
        canvas.worldCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
        if (canvas.worldCamera == null)
        {
            Debug.LogWarning(this.gameObject.transform.parent.name + " didnt get the camera.");
        }

    }
}


```