bool generateArena(LabyClass.Laby a, int longueur, int largeur) { for (int i = 0; i < longueur; i++) { GameObject limite1 = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube_Indestructible.prefab", typeof(GameObject))) as GameObject; GameObject limite2 = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube_Indestructible.prefab", typeof(GameObject))) as GameObject; GameObject limite3 = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube_Indestructible.prefab", typeof(GameObject))) as GameObject; GameObject limite4 = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube_Indestructible.prefab", typeof(GameObject))) as GameObject; limite1.transform.Translate(i + DemiCube, DemiCube, 0 - DemiCube); limite2.transform.Translate(i + DemiCube, DemiCube, 20 + DemiCube); limite3.transform.Translate(0 - DemiCube, DemiCube, i + DemiCube); limite4.transform.Translate(20 + DemiCube, DemiCube, i + DemiCube); for (int j = 0; j < largeur; j++) { switch (a.getValue(i, j)) { case "##": if (Random.Range(0, 100) > 20) { GameObject caisse = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube_Indestructible.prefab", typeof(GameObject))) as GameObject; caisse.transform.Translate(i + DemiCube, DemiCube, j + DemiCube); } else { GameObject caisse = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube.prefab", typeof(GameObject))) as GameObject; caisse.transform.Translate(i + DemiCube, DemiCube, j + DemiCube); } break; case " ": if (Random.Range(0, 100) < chanceCaisseArene) { GameObject caisse = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Cube.prefab", typeof(GameObject))) as GameObject; caisse.transform.Translate(i + DemiCube, DemiCube, j + DemiCube); } break; } } } return(true); }
void Start() { CaseClass = GetComponent <CaseClass>(); LabyClass = GetComponent <LabyClass>(); X = taillemap / 2; Y = taillemap / 2; LabyClass.Laby a = new LabyClass.Laby(X, Y); a.generer(); GameObject ground = GameObject.Instantiate(Resources.LoadAssetAtPath("Assets/Prefabs/Ground.prefab", typeof(GameObject))) as GameObject; ground.transform.localScale = new Vector3(2, 2, 2); ground.transform.position = new Vector3(X / 2, 0, Y / 2); if (generateArena(a, X, Y)) { Debug.Log("Generation du terrain terminée"); } else { Debug.Log("Error"); } }
void Start() { CaseClass = GetComponent<CaseClass>(); LabyClass = GetComponent<LabyClass>(); X = taillemap/2; Y = taillemap/2; LabyClass.Laby a = new LabyClass.Laby(X, Y); a.generer(); GameObject ground = GameObject.Instantiate( Resources.LoadAssetAtPath("Assets/Prefabs/Ground.prefab", typeof(GameObject)) ) as GameObject; ground.transform.localScale = new Vector3(2,2,2); ground.transform.position = new Vector3(X/2,0,Y/2); if(generateArena(a, X, Y)) Debug.Log("Generation du terrain terminée"); else Debug.Log("Error"); }