38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
|
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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|