・カメラの切り替え
各カメラのTagを[MainCamera]にしました。特にこのTagでないとだめということはありませんが、以降のスクリプトで使用するためそうしています。
GameObject-CreateEmptyでカメラコントロール用のオブジェクトを配置し、スクリプトを設定します。
以下のスクリプトを記述してみました。
using UnityEngine;
using System.Collections.Generic;
public class GameController : MonoBehaviour
{
private List<GameObject> cameras = new List<GameObject> ();
private int current_camera_index = 0;
// Use this for initialization
void Start ()
{
var objects = GameObject.FindGameObjectsWithTag ("MainCamera");
foreach (GameObject game_object in objects)
{
if (objects != null)
{
cameras.Add (game_object);
}
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Keypad5))
{
//参照カメラ切り替え
++current_camera_index;
if (cameras.Count <= current_camera_index)
{
current_camera_index = 0;
}
for (int i = 0; i < cameras.Count; ++i)
{
cameras[i].camera.enabled = i == current_camera_index;
}
}
}
}これで実行すれば5キーを押すたびにカメラが切り替わります。・画面分割
おまけで画面分割を。
カメラのNormilizedViewPortRectを編集すれば画面分割ができます。
例えばカメラを2つ配置し、
片方はX:0,Y:0,W:0.5,H:1、
もう一方をX:0.5,Y:0,W:0.5,H:1にすれば
簡単に画面を縦に割ることができます。

0 件のコメント:
コメントを投稿