Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class CreateEnemy2_1 : MonoBehaviour
- {
- public int MaxEnemyCount; //敵の最大数
- public Vector3 CreateRange; //敵を作る範囲
- public Transform CreateEnemy2_1T; //敵を発生させる原点
- public GameObject Enemy1Obj; //Enemy1オブジェクト
- // Use this for initialization
- void Start ()
- {
- for(int i = 0; i < MaxEnemyCount; i++)
- {
- GameObject Enemy1Objs = Instantiate(Enemy1Obj); //敵を生成
- float RandomCreateX = Random.Range(-CreateRange.x, CreateRange.x); //生成する範囲からランダムな座標を決める(X軸)
- float RandomCreateZ = Random.Range(-CreateRange.z, CreateRange.z); //生成する範囲からランダムな座標を決める(Z軸)
- Vector3 RandomCreate = new Vector3(RandomCreateX, 0, RandomCreateZ); //代入
- Enemy1Objs.transform.position = CreateEnemy2_1T.position + RandomCreate; //敵の発生場所を決める(発生させる原点にランダムに生成する範囲を足す)
- Enemy1Objs.GetComponent<NavMeshAgent>().enabled = true; //インスタンスと同時にNavMeshAgentを有効にする
- }
- }
- // Update is called once per frame
- void Update ()
- {
- }
- }
Add Comment
Please, Sign In to add comment