プレイヤーの周囲に敵の種類が複数現れるようにしたいのですが1種類しか現れません。
敵は2種類で猫とモンスターのプレファブをドラッグ&ドロップで登録してます。
Play↓
猫が出現すると猫しか表示されず
モンスターが出現するとエラー(猫のアニメーション"Idle"にインスタンスが入らない模様)
イメージは猫とモンスターがランダムで出現するようにしたいのですがそうなってくれません。
//EnemyService.cs public GameObject[] enemyPrefab; //インスペクターから2つ追加 private int number; void Start() { number = Random.Range(0, enemyPrefab.Length); } private void Enemy(EnemyLocation enemy) { enemy.gameObject = (GameObject)Instantiate(enemyPrefab[number], position, Quaternion.identity); } //Enemy.cs public class EnemyLocation { public Vector3 position; public GameObject gameObject; } //EnemyController.cs public Animation anim; public Animation nim; public float animationSpeed = 1; void Start() { anim = GetComponent<Animation>(); anim["Walk_Loop"].speed = animationSpeed; nim = GetComponent<Animation>(); nim["Idle"].speed = animationSpeed; //ここでエラー } //エラー NullReferenceException: Object reference not set to an instace of an object
究明できない為、お助けお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/30 13:16
2017/11/30 16:23