敵のステータスや攻撃パターンを簡単に設定できるツールを製作しています。
UnityEventを使うと関数を指定できますよね?このように指定できるものを作りたいのですが、スクリプト内の複数の関数を取ってきてList変数に保存しておく方法(関数を変数のように扱う)がわからないので知りたいです。
/// 渦巻き状 /// </summary> /// <returns></returns> private IEnumerator RollingShot() { while (true) { for(float i = 1; i <= 75; i+=0.5f) { for (float j = i; j < 360+i; j +=i) { var bullet1 = E_bullet.GetE_bullet(); bullet1.transform.rotation = Quaternion.Euler(bullet1.transform.rotation.x, bullet1.transform.rotation.y,j); bullet1.transform.position = this.transform.position; bullet1.SetActive(true); yield return new WaitForSeconds(0.01f); } } } } /// <summary> /// ランダム /// </summary> /// <returns></returns> private IEnumerator RandomShot() { while (true) { if (!Target.activeSelf) { StopShot(); } var bullet1 = E_bullet.GetE_bullet(); bullet1.transform.rotation = Quaternion.Euler(bullet1.transform.rotation.x, bullet1.transform.rotation.y, Random.Range(0,360)); bullet1.transform.position = this.transform.position; bullet1.SetActive(true); yield return null; } } /// <summary> /// ホーミング /// </summary> /// <returns></returns> private IEnumerator HomingShot() { Target = GameObject.FindWithTag("player"); while (true) { if (!Target.activeSelf) { StopShot(); } for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { var bullet1 = E_bullet.GetE_bullet(); PosX = this.transform.position.x - Target.transform.position.x; PosY = this.transform.position.y - Target.transform.position.y; bullet1.transform.rotation = Quaternion.Euler(bullet1.transform.rotation.x, bullet1.transform.rotation.y, -Mathf.Atan2(PosX, PosY) * Mathf.Rad2Deg); bullet1.transform.position = this.transform.position; bullet1.SetActive(true); yield return new WaitForSeconds(0.025f); } yield return new WaitForSeconds(0.05f); } yield return new WaitForSeconds(0.1f); } } /// <summary> /// つむじ /// </summary> /// <returns></returns> private IEnumerator SpecialShot() { while (true) { if (!Target.activeSelf) { StopShot(); } for (int i = 0; i < 360; i += 40) { for(int j = 0; j < 360; j += 90) { var bullet1 = E_bullet.GetE_bullet(); bullet1.transform.rotation = Quaternion.Euler(bullet1.transform.rotation.x, bullet1.transform.rotation.y, j+i); bullet1.transform.position = this.transform.position; bullet1.SetActive(true); yield return null; } yield return new WaitForSeconds(0.05f); } } } /// <summary> /// 円形 /// </summary> /// <returns></returns> private IEnumerator RoundShot() { while (true) { if (!Target.activeSelf) { StopShot(); } for (int i = 2; i < 5; i++) { for (int j = i; j < 360+i; j += 4) { var bullet1 = E_bullet.GetE_bullet(); bullet1.transform.rotation = Quaternion.Euler(bullet1.transform.rotation.x, bullet1.transform.rotation.y, j); bullet1.transform.position = this.transform.position; bullet1.SetActive(true); } yield return new WaitForSeconds(0.2f); } yield return new WaitForSeconds(1.0f); } } 追加予定の攻撃処理、これを変数で扱いたい
using
1using System.Collections.Generic; 2using System.IO; 3using UnityEngine; 4using UnityEngine.Events; 5 6public class BossInfo : MonoBehaviour 7{ 8 [SerializeField, Tooltip("体力/現在値")] 9 private float m_hp; 10 [SerializeField, Tooltip("体力/最大値")] 11 private float m_hp_max; 12 [SerializeField, Tooltip("ウェーブ数")] 13 private int m_wave; 14 public float hp { get { return m_hp; } set { m_hp = value; } } 15 public float max_hp { get { return m_hp_max; } set { m_hp_max = value; } } 16 public int wave { get {return m_wave; } set { m_wave = value; } } 17} 18敵の情報
using
1using System.Collections.Generic; 2using UnityEngine; 3using UnityEditor; 4 5[CustomEditor(typeof(BossInfo))] 6public class BossEditor : Editor 7{ 8 public override void OnInspectorGUI() 9 { 10 BossInfo boss = target as BossInfo; 11 12 EditorGUILayout.BeginVertical(GUI.skin.box); 13 EditorGUILayout.LabelField("ステータス"); 14 EditorGUILayout.BeginHorizontal(); 15 EditorGUILayout.LabelField("体力/現在値"); 16 boss.hp = EditorGUILayout.FloatField(boss.hp); 17 if (GUILayout.Button("Reset")) 18 { 19 Debug.Log("Reset"); 20 boss.hp = boss.max_hp; 21 } 22 EditorGUILayout.EndHorizontal(); 23 EditorGUILayout.BeginHorizontal(); 24 EditorGUILayout.LabelField("体力/最大値"); 25 boss.max_hp = EditorGUILayout.FloatField(boss.max_hp); 26 EditorGUILayout.EndHorizontal(); 27 EditorGUILayout.EndVertical(); 28 29 if( GUILayout.Button("Attck!!")) 30 { 31 boss.hp -= 1; 32 } 33 34 EditorGUILayout.BeginVertical(GUI.skin.box); 35 EditorGUILayout.LabelField("ウェーブ数"); 36 EditorGUILayout.BeginHorizontal(); 37 boss.wave = EditorGUILayout.IntField(boss.wave); 38 EditorGUILayout.EndHorizontal(); 39 EditorGUILayout.LabelField("攻撃変化"); 40 for (int i = 1; i <= boss.wave; i++) 41 { 42 EditorGUILayout.BeginVertical(GUI.skin.box); 43 EditorGUILayout.LabelField("Wave" + i); 44 //関数またはフォルダから攻撃を選ぶプルダウンを表示 45 //選ばれたらそれぞれの設定可能パラメータの表示 46 EditorGUILayout.EndVertical(); 47 } 48 EditorGUILayout.EndVertical(); 49 50 } 51 52} 53ボスEditor、攻撃を扱いたい部分
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。