1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawn_with_delay : MonoBehaviour {
public GameObject objet, empty;
public Material mater;
public Mesh mesh;
public float retard,pas_ligne,pas_colonne,pas_hauteur,position_depart,nombre_de_lignes,nombre_de_colonnes,nombre_de_hauteurs;//max;
int i=0;
int j=0;
int k=0;
List<GameObject> ObjectList;
void Start(){
ObjectList = new List<GameObject>();
ObjectList.Add(objet);
InvokeRepeating("Spawn", 0, retard);
}
// Use this for initialization
void Spawn () {
ObjectList = new List<GameObject>();
ObjectList.Add(objet);//toujours Add avant création dynamique avec new
ObjectList[0] = new GameObject("toto");
ObjectList[0].transform.parent = empty.transform; //ObjetList[0] est l'enfant de l'empty
ObjectList[0].transform.position = new Vector3(position_depart+i*pas_ligne,pas_hauteur*k,pas_colonne*j);
ObjectList[0].AddComponent<MeshRenderer>().material = mater;
ObjectList[0].AddComponent<MeshFilter>().mesh = mesh;
i++;
print("valeur de ième ligne: "+i);
print("valeur de jème colonne: "+j);
print("valeur de kème hauteur: "+k);
if(i>=Mathf.Floor(nombre_de_lignes-position_depart))
{
j++;
if(j>=Mathf.Floor(nombre_de_colonnes-position_depart))
{ k++;
if(k>=Mathf.Floor(nombre_de_hauteurs-position_depart))
{k=0;
//comment stopper ce script ici?
}
i = 0;
j = 0;
}
i = 0;
}
}
// Update is called once per frame
void Update () {
//for(i=0;i<max;i++)
//{
//}
}
} |
Partager