4
5

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.

unity > 外部ファイルで定数を定義したものを使う > include "xxx.h"の代わり

Last updated at Posted at 2015-08-13
動作確認
Unity 5.1.1-f1 on MacOS X 10.8.5

色々な設定を外部ファイルにもたせて、それをスクリプト内で使えないか調べていた。
以下のサイトが参考になった。
http://gamenosirusi.blog.fc2.com/blog-entry-12.html

C言語で.hファイルにconst宣言したものを色々な.cファイルでincludeして使うようなことをしたい。

手順

上記サイトと同じだが、こちらにも再掲する

まず、以下のようなスクリプトを作成する。

Common.cs
using UnityEngine;
using System.Collections;

namespace Common
{
	public static class Define
	{
		public const string callingScene = "Scene1";
	}
}

using Common;すると Define.callingSceneを使うと"Scene1"になる。

使用例
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using Common; // for Define.XXX

public class SelectButtonControl : MonoBehaviour {
	
	public void ButtonSelector() {
//		Application.LoadLevel ("Scene1");
		Application.LoadLevel (Define.callingScene);
	}
}
4
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?