Unity 2017.3f1を使用してRPGゲームのターン制システムを実装しようとしているのですが、
NullReferenceException: Object reference not set to an instance of an object
TurnController.Update () (at Assets/Scripts/TurnController.cs:27)
というエラーが出てしまってなかなか解決できません。
1ターンに置ける行動とをを1アクションとして、アクションのキューを作って一つ一つ実行しようとしています。
エラーしたから5行目のwaitAction.fight()のところで生じているようです。
よろしくお願いします。
以下がソースコードです。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurnController : MonoBehaviour {
public BattleChara[] playerList;
public Queue<ActionController> waitActions;
public GameObject Action;
// Use this for initialization
void Start ()
{
Queue<ActionController> waitActions = new Queue<ActionController>();
int length = playerList.Length;
int i;
for (i = 0; i < length; i++)
{
GameObject action = Instantiate(Action);
ActionController a = action.GetComponent<ActionController>();
a.attacker = playerList[i];
a.defender = playerList[Random.Range(0, length)];
waitActions.Enqueue(a);
}
}
// Update is called once per frame
void Update () {
foreach(ActionController waitAction in waitActions)
{
waitAction.fight();
waitActions.Dequeue();
}
}
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。