Created
December 21, 2014 11:01
-
-
Save kankikuchi/b4e09c4bdef1bb99dbcc to your computer and use it in GitHub Desktop.
モンスター自動生成【Unity】
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MonsterMaker : MonoBehaviour { | |
//モンスターデータがあるディレクトリのパス | |
public const string MONSTER_DATA_PATH = "Data/"; | |
void Awake () { | |
//ステージ番号を設定(する処理が入るが、今は特にないので1) | |
int stageNo = 1; | |
//モンスターデータを取得する | |
MonsterData monsterData = Resources.Load<MonsterData> (MONSTER_DATA_PATH + stageNo); | |
if(monsterData == null){ | |
Debug.Log ("モンスターデータが生成されていません"); | |
return; | |
} | |
if(monsterData.list.Count == 0){ | |
Debug.Log ("モンスターデータに登録されているモンスターが0です"); | |
return; | |
} | |
//登録されているデータの数だけモンスターを生成、各データを設定 | |
foreach(MonsterData.Param param in monsterData.list){ | |
GameObject monster = new GameObject (); | |
monster.name = param.GameObjectName; | |
monster.transform.position = param.Position; | |
monster.transform.rotation = param.Rotation; | |
monster.AddComponent<SetMonsterStatus> (); | |
monster.GetComponent<SetMonsterStatus> ().Type = param.Type; | |
monster.GetComponent<SetMonsterStatus> ().HP = param.HP; | |
monster.GetComponent<SetMonsterStatus> ().MP = param.MP; | |
monster.GetComponent<SetMonsterStatus> ().Power = param.Power; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment