public void createDinamicCard(GameObject go, string player, Player jug) { var monsterCollection = MonsterContainer.Load(Path.Combine(Application.dataPath, "monsters.xml")); GameObject c = (GameObject)Instantiate(card); int it = Random.Range(0, monsterCollection.Monsters.Length); foreach (Transform data in c.transform) { if (data.name == "name") { Text t = data.GetComponent <Text> (); t.text = monsterCollection.Monsters [it].getName(); c.name = monsterCollection.Monsters [it].getName(); } if (data.name == "Attack") { Text t = data.GetComponentInChildren <Text> (); t.text = monsterCollection.Monsters [it].getAtk().ToString(); } if (data.name == "Defense") { Text t = data.GetComponentInChildren <Text> (); t.text = monsterCollection.Monsters [it].getHealth().ToString(); } if (data.name == "cost") { Text t = data.GetComponentInChildren <Text> (); t.text = monsterCollection.Monsters [it].getCost().ToString(); } } c.transform.SetParent(go.transform, false); c.tag = player; if ((player == "Player1" && !turnPlayer1) || (!isUsableThisCard(c, jug))) { c.GetComponent <draggable> ().enabled = false; Image img = c.GetComponent <Image> (); img.color = Color.red; } else if ((player == "Player2" && !turnPlayer2) || (!isUsableThisCard(c, jug))) { c.GetComponent <draggable> ().enabled = false; Image img = c.GetComponent <Image> (); img.color = Color.red; } else { Image img = c.GetComponent <Image> (); img.color = Color.green; } }
// Start is called before the first frame update void Start() { var monsterCollection = MonsterContainer.Load(Path.Combine(Application.dataPath, "RealFram/xmlTest/monsters.xml")); Monster[] m_monsters = monsterCollection.Monsters; Debug.Log(m_monsters[0].Name); Debug.Log(m_monsters[0].Health); Debug.Log(m_monsters[0].Description); Debug.Log(m_monsters[0].Funny); var monsterCollection2 = new MonsterContainer(); monsterCollection2.Monsters = new Monster[1]; Monster mMonter = new Monster(); mMonter.Name = "test2"; mMonter.Health = 10; mMonter.Funny = "heyhey"; mMonter.Description = "running away"; monsterCollection2.Monsters[0] = mMonter; monsterCollection2.Save(Path.Combine(Application.dataPath, "RealFram/xmlTest/monsters.xml")); }