18. [Range( , )]
範囲を制限する
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log (level);
}
}
20. Tips
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject obj;
public int count;
// Use this for initialization
void Start () {
for (int i = 0; i< count; i++) {
Instantiate(obj, new Vector3(Random.Range(-5,5),Random.Range(-5,5),Random.Range(-
5,5)),transform.rotation);
}
}
}
値の範囲を指定する必要があるのは、例えば上記のcountに1000など入れてしまうと処理落ちする場合
がありますね。しかし、値の範囲を設定すれば安全ですね。
21. [Multiline( )]
入力用のスペースを作る
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log (level);
Debug.Log (message);
}
}
23. [HideInInspector]
publicにした変数でもInspector viewから変更できなくする
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
// Use this for initialization
void Start () {
Debug.Log (x);
}
// Update is called once per frame
void Update () {
Debug.Log (level);
Debug.Log (message);
}
}
24. [HideInInspector]
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
// Use this for initialization
void Start () {
Debug.Log (x);
}
// Update is called once per frame
void Update () {
Debug.Log (level);
Debug.Log (message);
}
}
25. [SerializeField]
privateの変数でもInspector viewから変更できます。
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
[SerializeField] private int y = 5;
// Use this for initialization
void Start () {
Debug.Log (x);
Debug.Log (y);
}
}
26. [Space( )]スペースを作る
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
[SerializeField] private int y = 5;
[Space(10.0f)]public float figure = 30;
// Use this for initialization
void Start () {
Debug.Log (x);
Debug.Log (y);
}
// Update is called once per frame
void Update () {
Debug.Log (level);
Debug.Log (message);
}
}
27. [Header(“ ”)]
ヘッダー追加します
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
[SerializeField] private int y = 5;
[Header("プレイヤーのスピード")]
[Space(10.0f)]public float speed = 30;
// Use this for initialization
void Start () {
Debug.Log (x);
Debug.Log (y);
}
// Update is called once per frame
void Update () {
Debug.Log (level);
Debug.Log (message);
}
}
28. [TooltipAttribute("String")]
ポインターを上に持ってくると表示されます。
using UnityEngine;
using System.Collections;
public class HelloExtension : MonoBehaviour {
[Range(1,100)]public int level = 1;
[Multiline(5)]public string message;
[HideInInspector] public int x = 10;
[SerializeField] private int y = 5;
[Header("プレイヤーのスピード")]
[Space(10.0f)]public float speed = 30;
[SerializeField, TooltipAttribute("プレイヤーのライフ")]
int health;