4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity3Dで、スクリプトからカメラを新規作成する

Last updated at Posted at 2013-08-05

Projectビューで、Assetsを右クリック->Create->FolderでEditorというフォルダを作成して、
そこに以下の内容で、MyMenu.csというスクリプトファイルを作成する。

MyMenu.cs
using UnityEditor;
using UnityEngine;

public class MyMenu : MonoBehaviour
{
	private  static Camera _cam;

	//  Add a menu item named "Create/Camera" to McGUI in the menu bar.
	[MenuItem ("MyMenu/Create/Camera")]
	static void CreateCamera ()
	{
		GameObject obj = UnityEditor.EditorUtility.CreateGameObjectWithHideFlags("Camera", HideFlags.None, typeof(Camera));
		_cam = obj.camera;
	}
}

すると、Unityのメニューに"MyMenu"が現れるので、
MyMenu->Create->Camera
を選択することによりカメラが作成される。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?