간단한 프로토타입용 스포너 스크립트 구현.






















간단한 프로토타입용 스폰 스크립트.

Zombie : 스폰 게임오브젝트 등록.
Time Spawn : 다음 스폰 리스트 인터벌.
Enemy Count : 스폰 시킬 적의 최대 .
Spawn Pos : 스폰 위지.
Tag Name : 스폰 게임오브젝트에 사용자 Tag 입히기. - > 이건 안에서 해당 테크를 검사 하여 현재 안의 타입별 적이 몇인지를 알기 위한 테그.
Offset X : 스폰 포지션 x 벡터에 대한+ 렌덤 변수 (- , +)
Offset Z : 스폰 포지션 z 벡터에 대한 + 렌덤 변수 (- , +)

using UnityEngine;
using System.Collections;
//using System.Collections.Generic;

public enum ZombieTagList { Melee , Dash , Boss };

public class SpawnerZombie : MonoBehaviour {
 
 public GameObject Zombie;
 private float timetemp = 0;
 public float timeSpawn = 3;
 public int enemyCount = 0;
 public Transform spawnPos;
 public ZombieTagList TagName =  ZombieTagList.Melee;
 private Vector3 offsetVctor;
 public float offsetX , offsetZ;




 void Start () 
 {
  if(spawnPos == null)spawnPos = GetComponent(typeof(Transform)) as Transform;

  if(renderer)
   renderer.enabled = false;
  timetemp = Time.time;

  GameObject go = new GameObject();
  go.gameObject.tag = TagName.ToString();

  Zombie.tag = go.tag;


 }
 
 void Update () 
 {
  GameObject[] gos = GameObject.FindGameObjectsWithTag(Zombie.tag);
  if(gos.Length < enemyCount)
  {
   if(Time.time > timetemp+timeSpawn)
   {
    timetemp = Time.time;
    OffsetVectorFunc ();
    GameObject.Instantiate(Zombie , (spawnPos.position + offsetVctor) , Quaternion.AngleAxis(-90,Vector3.up));


   }
  }
       
 }

 protected void OffsetVectorFunc()
 {
  offsetVctor = new Vector3 ();
  offsetVctor.x = Random.Range(-offsetX , offsetX);
  offsetVctor.z = Random.Range(-offsetZ , offsetZ);
 }


}


Game Developer Leegoon copyright all right reserved since 2010.

Comments