Dossier complet
This commit is contained in:
37
Droid 2/Assets/MeteorRain.cs
Normal file
37
Droid 2/Assets/MeteorRain.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MeteorRain : MonoBehaviour {
|
||||
|
||||
[SerializeField] private GameObject meteorPrefab; // Préfab pour les météorites
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(5f);
|
||||
Create(); // Appelle la méthode pour créer une météorite
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour créer une météorite
|
||||
private void Create()
|
||||
{
|
||||
// Instancie une nouvelle météorite à la position de MeteorRain
|
||||
GameObject meteor = Instantiate(meteorPrefab, transform.position, transform.rotation);
|
||||
|
||||
// Applique une force aléatoire pour la trajectoire de la météorite
|
||||
Rigidbody meteorRigidbody = meteor.GetComponent<Rigidbody>();
|
||||
if (meteorRigidbody != null)
|
||||
{
|
||||
Vector3 randomForce = new Vector3(
|
||||
Random.Range(-10.0f, 10.0f), // Force horizontale aléatoire
|
||||
Random.Range(-10.0f, 0f), // Force verticale aléatoire
|
||||
0f // Pas de force en profondeur
|
||||
);
|
||||
meteorRigidbody.AddForce(randomForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user