// Use this for initialization void Start() { //On instantie le joueur PlayerAvatar temp = Instantiate(player); //On prépare l'événemment de fin de jeu temp.OnPlayerDeath += OnGameOver; //On calcule les dimensions de la fenetre de jeu height = Camera.main.orthographicSize; width = height * Camera.main.aspect; //On crée le décor for (int i = 0; (i - 2) * 20.48 < width; i++) { Instantiate(background, new Vector3(i * 20.48f + 10.24f - width, 0, 1), transform.rotation); } //On modifie ces valeurs pour assurer que les ennemis sont créés hors de la fenetre height -= enemy.GetComponent <Renderer> ().bounds.size.x / 2f; width += enemy.GetComponent <Renderer> ().bounds.size.y / 2f; //On initialise le temps pour créer les ennemis timeOfNextEnemyInstantiation = Time.time; //WriteDataInXML ("test_data2.xml"); //à ignorer, j'avais juste la flemme d'écrire un XML à la main if (levelTextAsset) { LoadFromXML(levelTextAsset); } }
void FireAtRandomTimes() { enemy.GetComponent <BulletGun>().Fire(); }
// Update is called once per frame void Update() { //Instantiation des collectables if (Time.time > timeOfNextCollectibleInstantiation) { //On réinitialise le temps d'attente timeOfNextCollectibleInstantiation += collectibleApparitionCooldown; //On prépare le collectables qu'on va instantier en le choisissant Collectibles toInstantiate; float index = Random.Range(0, weaponCollectibleApparitionRatio + healthCollectibleApparitionRatio + energyCollectibleApparitionRatio); //Selon le nombre tiré, on initialise tel ou tel collectable if (index < weaponCollectibleApparitionRatio) { toInstantiate = weaponCollectible; } else if (index < weaponCollectibleApparitionRatio + healthCollectibleApparitionRatio) { toInstantiate = healthCollectible; } else { toInstantiate = energyCollectible; } //On l'instantie Instantiate(toInstantiate, new Vector3(width, Random.Range(-height, height), 0), transform.rotation); } //Selon le mode de jeu on emploi telle ou telle méthode pour instantier un ennemi if (GameModeWithHealth) { if (levelTextAsset == null) { //Si il n'y a pas de niveau à chaerger, utiliser les valeurs de l'éditeur Unity if (Time.time > timeOfNextEnemyInstantiation && numberOfEnemyInstantiated < numberOfEnemyInLevel) { timeOfNextEnemyInstantiation += enemyCooldown; EnemyAvatar temp = EnemyFactory.Instance.GetEnemy(); temp.SetPosition(new Vector2(width, Random.Range(-height, height))); //On décide de la nature du mouvement de l'ennemi temp.GetComponent <AIEnemyBasicEngine> ().zigzag = (1 == Random.Range(0, 2)); //On prépare l'événement de sa mort temp.OnEnemyDeath += OnEnemyDeath; temp.OnEnemyDeath += UIManager.OnEnemyDeath; //On met à jour le nombre d'ennemis déjà instanciés numberOfEnemyInstantiated++; } } else //Sinon utiliser les données du XML donné { Debug.Log("prout"); if (Time.time > timeOfNextEnemyInstantiation && numberOfEnemyInstantiated < numberOfEnemyInLevel) { timeOfNextEnemyInstantiation += timeBetweenThisAndPreviousEnemy[numberOfEnemyInstantiated]; EnemyAvatar temp = EnemyFactory.Instance.GetEnemy(); temp.SetPosition(new Vector2(width, enemiesVerticalSpawnPositions[numberOfEnemyInstantiated])); numberOfEnemyInstantiated++; temp.GetComponent <AIEnemyBasicEngine> ().zigzag = (1 == Random.Range(0, 2)); temp.OnEnemyDeath += OnEnemyDeath; temp.OnEnemyDeath += UIManager.OnEnemyDeath; } } } else if (!GameModeWithHealth) { if (Time.time > timeOfNextEnemyInstantiation) { timeOfNextEnemyInstantiation += enemyCooldown; //EnemyAvatar temp = Instantiate (enemy, new Vector3 (width, Random.Range (-height, height), 0), transform.rotation); EnemyAvatar temp = EnemyFactory.Instance.GetEnemy(); temp.SetPosition(new Vector2(width, Random.Range(-height, height))); temp.GetComponent <AIEnemyBasicEngine>().zigzag = (1 == Random.Range(0, 2)); temp.OnEnemyDeath += OnEnemyDeath; temp.OnEnemyDeath += UIManager.OnEnemyDeath; } } }