Unity でシーンを作成すると、最初にカメラが 1 つ含まれています。ほとんどの場合、それだけで十分です。ただし、シーン内に好きなだけカメラを持つこともできます。それらカメラのビューは以下で説明するように、さまざまな方法で組み合わせることができます。
デフォルトでは、1 つのカメラがそのビューを描画すると、画面全体が覆われます。つまり、1 度に映せるカメラのビューは 1 つだけです ( Depth プロパティで最も高い値を持つカメラのビューが描画されます)。スクリプトであるカメラをオフにして他のカメラをオンにすることで、カメラから別のカメラへシーンビューの「切り替え」ができます。例えば、上方からのマップのビューと一人称視点のビューを切り替えることができます。
using UnityEngine;
public class ExampleScript : MonoBehaviour {
public Camera firstPersonCamera;
public Camera overheadCamera;
// FPS カメラを使用不可にするためには、この関数を呼び出し
// オーバーヘッドカメラを使用可能にします
public void ShowOverheadView() {
firstPersonCamera.enabled = false;
overheadCamera.enabled = true;
}
// FPS カメラを使用可能にするためには、この関数を呼び出し
// オーバーヘッドカメラを使用不可にします
public void ShowFirstPersonView() {
firstPersonCamera.enabled = true;
overheadCamera.enabled = false;
}
}
通常 (デフォルト設定では)、少なくとも 1 つのカメラビューが画面全体を覆いますが、画面内の一部の小さな領域で別のビューを表示することが役に立つことがあります。例えば、主要なビューは一人称視点の画面を表示する一方、ドライビングゲーム内でバックミラーを表示したり、上方からのミニマップを画面端に表示することができます。Viewport Rect プロパティを使用して、画面上でのカメラビューの大きさを設定することができます。
ビューポートの座標は画面に対して「正規化」されます。左下の角が 0.0 座標、右上の角が1.0 になります。0.5 の値がその中間です。ビューポートサイズに加えて、小画面用カメラの Depth プロパティ値は、背景のカメラよりも高く設定すべきです。正確な値は重要ではありませんが、より高い Depth 値を持つカメラは、低い Depth 値のカメラの上に重ねて描画されます
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.