ãUnity9ãUNETã§ã¾ã³ãçºçå°ç¹ãå¢ãããUNET17ã
Unity5.1.1p3 Personal(2015å¹´7æ)
前回の続きã§ãã
ä»ã®ã¨ããã¾ã³ãçºçå°ç¹ã1ç®æããç¡ãã®ã§ã4ã¤ã«å¢ããã¦ããã¾ãã
ã¾ããæéå·®ã§å°ããã¤åºç¾ããããã«ãã¦ããã¾ãã
UNET Part 17 - Better Spawning - YouTube
ãç®æ¨ãã¾ã³ãçºçå°ç¹ãå¢ãã
â ã¾ã³ãçºçå°ç¹ã4ã¤ã«å¢ãã
ã¾ãã¯ã¾ã³ããçºçå°ç¹ãå¢ããã¦ããã¾ãã
Mainã·ã¼ã³ã«ã¦ç©ºã®GameObjectãä½æãã¦ãååããZombie_SpawnGroupãã«ãã¦ä¸ããã
ç¶ãã¦æ¢åã®ZombieSpawnãªãã¸ã§ã¯ãã4ã¤ã«ã³ãã¼ãã¦ãZombie_SpawnGroupãªãã¸ã§ã¯ãã®åãªãã¸ã§ã¯ãã«ãã¦ä¸ããã
ã³ãã¼ãã¦åãªãã¸ã§ã¯ãã«ãã
åZombieSpawnãªãã¸ã§ã¯ãã«ãZombieSpawnãã¨ããã¿ã°ãä»ãã¾ãã
ã¾ããå ´æãå°ããã¤ãã©ãããã¾ãããã
ZombieSpawn
ZombieSpawn(1)
ZombieSpawn(2)
ZombieSpawn(3)
â¡GameManager_ZombieSpawnerã¹ã¯ãªããã®ä¿®æ£
ç¶ãã¦ä»¥åä½æããGameManager_ZombieSpawnerã¹ã¯ãªãããä¿®æ£ãã¦ããã¾ãã以ä¸ã½ã¼ã¹ã§ãã
using UnityEngine; using System.Collections; using UnityEngine.Networking; public class GameManager_ZombieSpawner : NetworkBehaviour { [SerializeField] GameObject zombiePrefab; //********** éå§ **********// //é åã«ä¿®æ£ //[SerializeField] GameObject zombieSpawn; private GameObject[] zombieSpawns; //********** çµäº **********// private int counter; private int numberOfZombies = 20; //********** éå§ **********// private int maxNumberOfZombies = 80; //ã¾ã³ãã®æå¤§æ° private float waveRate =10; //ã¾ã³ããåºç¾ããéé(ç§) //åºç¾ãã©ã° ä»åã¯ãã£ã¨trueã®ã¾ã¾ private bool isSpawnActivated = true; //********** çµäº **********// public override void OnStartServer () { //********** éå§ **********// // for (int i = 0; i < numberOfZombies; i++) { // SpawnZombies (); // } //ã¾ã³ãçºçå°ç¹ãåå¾ zombieSpawns = GameObject.FindGameObjectsWithTag("ZombieSpawn"); //ã³ã«ã¼ãã³ StartCoroutine(ZombieSpawner()); //********** çµäº **********// } //********** éå§ **********// IEnumerator ZombieSpawner () { //ç¡éã«ã¼ã for (;;) { //10ç§å¾ æ© yield return new WaitForSeconds (waveRate); //ã²ã¼ã ä¸ã®å ¨ã¾ã³ãåå¾ GameObject[] zimbies = GameObject.FindGameObjectsWithTag ("Zombie"); //ã¾ã³ãã®æ°ãæ大å¤ããå°ãªãã£ããã¡ã½ããå®è¡ if (zimbies.Length < maxNumberOfZombies) { CommenceSpawn(); } } } void CommenceSpawn () { if (isSpawnActivated) { //20åã«ã¼ã for (int i = 0; i < numberOfZombies; i++) { //0ã3ããã©ã³ãã ã§é¸ãã ã¾ã³ãçºçå°ç¹ã®ä½ç½®æ å ±ãå¼æ°ã«ã¡ã½ããå®è¡ int randomIndex = Random.Range(0, zombieSpawns.Length); SpawnZombies(zombieSpawns[randomIndex].transform.position); } } } //********** çµäº **********// //********** éå§ **********// //void SpawnZombies () void SpawnZombies (Vector3 spawnPos) //********** çµäº **********// { counter++; //********** éå§ **********// //GameObject go = GameObject.Instantiate(zombiePrefab, zombieSpawn.transform.position, Quaternion.identity) as GameObject; //å¼æ°ã®ä½ç½®ã«ã¾ã³ãçæ GameObject go = GameObject.Instantiate(zombiePrefab, spawnPos, Quaternion.identity) as GameObject; //********** çµäº **********// NetworkServer.Spawn(go); go.GetComponent<Zombie_ID>().zombieID = "Zombie " + counter; } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
GameManager_ZombieSpawner.cs
ã¾ãã¯Zombieãã¬ããã«ãZombieãã¿ã°ãä»ãã¾ãã
Zombieã¿ã°
OnStartServerã¡ã½ããã«ã¦ã¾ã³ãçºçå°ç¹4ç®æãåå¾ããã³ã«ã¼ãã³ãå®è¡ãã¾ãã
ã³ã«ã¼ãã³å ã§ã¯10ç§ãã¨ã«ãå ´ã®ã¾ã³ãæ°ãmaxNumberOfZombies(ããã©ã«ãã ã¨80å¼ã)ããå°ãªããã°CommenceSpawnã¡ã½ãããå®è¡ãã¾ãã
CommenceSpawnã¡ã½ããå ã§ã¯ã©ã³ãã ã§é¸ãã ã¾ã³ãçºçç®æã®ä½ç½®æ å ±ãå¼æ°ã«ãSpawnZombiesã¡ã½ãããå®è¡ãã¾ããã¨ããã®ã20åç¹°ãè¿ãã¾ãã
SpawnZombiesã¡ã½ããå
ã®ä¿®æ£ã¯ãçæããã¾ã³ãã®ä½ç½®æ
å ±ãå¼æ°ã«å¤ããã¨ããä¿®æ£ã®ã¿ã§ãã
â¢çµæ
ããã§ã¯ã²ã¼ã ãå®è¡ãã¦ã¿ã¾ãããã
ã¾ã³ãçºç
ã²ã¼ã éå§å¾10ç§ã§ã20å¹ã®ã¾ã³ããã©ã³ãã ãªä½ç½®ããçºçãã¾ããã
ãã®10ç§å¾ã«ãåãã20å¹ã®ã¾ã³ããçºçãã¾ããæåã§ãã
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ãUnity9ãUNETã§ãã«ããã¬ã¤ã¤ã¼ãªãªã³ã©ã¤ã³ã²ã¼ã éçºãUNET1ã
ãUnity9ãUNETã§ãã¬ã¤ã¤ã¼ã®åããè£éãããªããããªåããå®ç¾ãããUNET1-2ã
ãUnity9ãUNETã§ãããã¯ã¼ã¯è¶ãã«å¾ã(Rotation)ãåæããããUNET2ã
ãUnity9ãUNETã§ãªã³ã©ã¤ã³éå§æã®ãã¬ã¤ã¤ã¼çæä½ç½®ãå¤æ´ãããUNET2-2ã
ãUnity9ãUNETã®ãããã¯ã¼ã¯ãã©ãã£ãã¯ã軽æ¸ããå¹çåãããUNET3ã
ãUnity9ãUNETã®latency(é
延æé)ãæ¹åãããUNET4ã
ãUnity9ãUNETã®latency(é
延æé)ã表示ãã¦ãã¡ãã£ã¨ã ãæ¹åãããUNET4-2ã
ãUnity9ãUNETã®SyncVarã®hookã®ä½¿ç¨ä¾ã¨ãåæ代ã®åææ¹æ³ãUNET5ã
ãUnity9ãUNETã使ã£ã¦RotationãåæããããUNET6ã
ãUnity9ãUNETã§åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãããUNET7ã
ãUnity9ãUNETã§æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããï¼ãUNET8ã
ãUnity9ãUNETã§HPãç»é¢ã«è¡¨ç¤ºããPlayerã¸ãã¡ã¼ã¸ãä¸ãããUNET9ã
ãUnity9ãUNETã§HPã0以ä¸ã«ãªã£ãæãPlayerãç ´å£ããï¼ãUNET10ã
ãUnity9ãUNETã§æ»ãã Playerãçãè¿ãããï¼ãUNET11ã
ãUnity9ãUNETã§ã¾ã³ãAIãåºç¾ãããï¼ãUNET12ã
ãUnity9ãUNETã§ã¾ã³ãçææã«ã¦ãã¼ã¯ãªIDãä»ããï¼ãUNET13ã
ãUnity9ãUNETã§ã¾ã³ããæã¤ï¼ãUNET14ã
ãUnity9ãUNETã§ã¾ã³ãã«æ»æãããï¼ãUNET15ã
ãUnity9ãUNETã§ã¾ã³ãã®åããã¹ã ã¼ãºã«ã·ã³ã¯ããããï¼ãUNET16ã
ãUnity9ãUNETã§ã¾ã³ãçºçå°ç¹ãå¢ãããUNET17ã
ãUnity9ãUNETã§çºçãããã°ãåãé¤ããUNET18ã
ãUnity9ãUnity MultiPlayerã使ã£ã¦ãããã¯ã¼ã¯è¶ãã«ãããã¡ã¤ãã³ã°ï¼ãUNET19ã
ãUnity9ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼ãUNET20ã
ãUnity9ã表示ããGUI(Network Manager)ãæ©è½ãããï¼ãUNET20-2ã
ãUnity9ãUNETã§Animationãåæãããï¼ãUNET21ã