###前提・実現したいこと
Unityの3Dゲームにて、固定の出現場所からの敵のランダム生成をしようと考えています。
実装したいこととしては、
・フィールド内のいくつかの固定位置から、ランダムに敵を生成する
・生成に関して上限を定める
固定位置に関しては、出現場所のオブジェクトを作り、それをコピーしてフィールド内に配置していこうと思っています。
こちらの記事を参考にしているのですが、Java→C#の変換で詰まっています。
###発生している問題・エラーメッセージ
翻訳サイトを使っているのですが、Appear と length にエラーが起きています。
また、サイトでの自動翻訳を使っているため、本当に合っているかも分からない状態です。
###該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Appear : MonoBehaviour 6{ 7 public GameObject obj; 8 private GameObject[] objs; 9 public int max; 10 public float appearTime; 11 public int total; 12 private int num; 13 private float currentTime; 14 15 16 void Start() 17 { 18 objs = new GameObject[max]; 19 currentTime = 0.0f; 20 num = 0; 21 } 22 23 void Update() 24 { 25 objs = new GameObject[max]; 26 currentTime = 0.0f; 27 num = 0; 28 29 if (num < total) 30 { 31 currentTime += Time.deltaTime; 32 if (currentTime > appearTime) 33 { 34 appear(); 35 } 36 } 37 { 38 if (num < total) 39 { 40 41 currentTime += Time.deltaTime; 42 43 if (currentTime > appearTime) 44 { 45 appear(); 46 } 47 } 48 } 49 50 void Appear() 51 { 52 for (int i = 0; i < objs.length; i++) 53 { 54 if (objs[i] == null) 55 { 56 objs[i] = GameObject.Instantiate(obj); 57 num++; 58 break; 59 } 60 } 61 currentTime = 0.0f; 62 { 63 for (int i = 0; i < objs.length; i++) 64 { 65 if (objs[i] == null) 66 { 67 objs[i] = GameObject.Instantiate(obj); 68 num++; 69 break; 70 } 71 } 72 currentTime = 0.0f; 73 } 74 } 75 } 76}
見づらくて申し訳ありません。
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/16 21:32
2017/12/17 13:07