敵の種類を増やす例です。
EnemyGenerator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyGenerator : MonoBehaviour { public GameObject enemyPrefab; public GameObject enemyPrefab2; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Random.Range(0, 300) == 1) { Vector3 pos = new Vector3(Random.Range(-2.8f, 2.8f), 5.5f, 0); Instantiate(enemyPrefab, pos, Quaternion.identity); } if (Random.Range(0, 100) == 1) { Vector3 pos = new Vector3(Random.Range(-2.8f, 2.8f), 5.5f, 0); Instantiate(enemyPrefab2, pos, Quaternion.identity); } } } |
敵2のプレハブをGameMainにアタッチ。

コメント