Files
SpaceDroid/Droid 2/Assets/Meteorite.cs

35 lines
997 B
C#
Raw Permalink Normal View History

2025-01-17 13:04:56 +01:00
using UnityEngine;
public class Meteorite : MonoBehaviour
{
private UIManager UIManager;
// Direction et force de la chute
private Vector3 fallDirection = new Vector3(0.5f, -0.7f, 0);
public float fallSpeed = 10f;
void Start() {
UIManager = FindObjectOfType<UIManager>();
}
// Méthode appelée à chaque frame pour faire avancer la météorite
void Update()
{
// Déplace la météorite dans la direction définie
transform.position += fallDirection * fallSpeed * Time.deltaTime;
}
// Méthode appelée lorsque la météorite touche un objet
private void OnCollisionEnter(Collision collision)
{
// Détruit l'objet touché
Debug.Log($"{collision.gameObject.name} destroyed by Meteorite!");
Destroy(collision.gameObject);
}
private void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
StartCoroutine(UIManager.GameOverSequence());
}
}
}