Téléverser les fichiers vers "/"
This commit is contained in:
parent
894b5fe491
commit
f89c8b5f6d
27
BlackHole.cs
Normal file
27
BlackHole.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class BlackHole : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Vitesse de rotation du trou noir
|
||||||
|
public float rotationSpeed = 10f;
|
||||||
|
|
||||||
|
// Méthode appelée à chaque frame pour faire tourner le trou noir
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
transform.Rotate(0, rotationSpeed * Time.deltaTime, 0);
|
||||||
|
}
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
// Vérifie si le droïde ou tout autre objet entre dans le trou noir
|
||||||
|
if (other.gameObject.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
Debug.Log("Droid destroyed by Black Hole!");
|
||||||
|
Destroy(other.gameObject); // Détruit le droïde
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log($"{other.gameObject.name} destroyed by Black Hole!");
|
||||||
|
Destroy(other.gameObject); // Détruit tout autre objet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
139
Droid.cs
Normal file
139
Droid.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class Droid : MonoBehaviour
|
||||||
|
{
|
||||||
|
private bool jumpKeyWasPressed;
|
||||||
|
private float horizontalInput;
|
||||||
|
private bool isGrounded;
|
||||||
|
private Rigidbody rigidbodyComponent;
|
||||||
|
|
||||||
|
private int energyDisksCollected = 0;
|
||||||
|
private float speedMultiplier = 1f;
|
||||||
|
private float jumpMultiplier = 1f;
|
||||||
|
private bool isInvincible = false; // Empêche les dégâts multiples
|
||||||
|
|
||||||
|
|
||||||
|
[SerializeField] private int life = 2; // Niveau de vie initial
|
||||||
|
[SerializeField] private GameObject fusee;
|
||||||
|
[SerializeField] private UIManager uiManager;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
rigidbodyComponent = GetComponent<Rigidbody>();
|
||||||
|
|
||||||
|
// Recherche automatique du UIManager
|
||||||
|
if (uiManager == null)
|
||||||
|
{
|
||||||
|
uiManager = FindObjectOfType<UIManager>();
|
||||||
|
if (uiManager == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("UIManager is not assigned and could not be found in the scene!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
jumpKeyWasPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
horizontalInput = Input.GetAxis("Horizontal");
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.S))
|
||||||
|
{
|
||||||
|
LaunchRocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifie si le droïde tombe sous -10 en Y
|
||||||
|
if (transform.position.y < -10)
|
||||||
|
{
|
||||||
|
TriggerGameOver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FixedUpdate()
|
||||||
|
{
|
||||||
|
rigidbodyComponent.velocity = new Vector3(horizontalInput * 2 * speedMultiplier, rigidbodyComponent.velocity.y, 0);
|
||||||
|
|
||||||
|
if (jumpKeyWasPressed && isGrounded)
|
||||||
|
{
|
||||||
|
rigidbodyComponent.AddForce(Vector3.up * 5 * jumpMultiplier, ForceMode.VelocityChange);
|
||||||
|
jumpKeyWasPressed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionStay(Collision collision)
|
||||||
|
{
|
||||||
|
isGrounded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionExit(Collision collision)
|
||||||
|
{
|
||||||
|
isGrounded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator InvincibilityDelay()
|
||||||
|
{
|
||||||
|
isInvincible = true; // Active l'invincibilité
|
||||||
|
yield return new WaitForSeconds(1.0f); // Attendre 1 seconde (modifiable)
|
||||||
|
isInvincible = false; // Désactive l'invincibilité
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.layer == 8) // Disques énergétiques
|
||||||
|
{
|
||||||
|
Destroy(other.gameObject);
|
||||||
|
energyDisksCollected++;
|
||||||
|
life++; // Augmente la vie
|
||||||
|
Debug.Log("Vie augmentée : " + life);
|
||||||
|
|
||||||
|
// Augmente les capacités après 3 disques collectés
|
||||||
|
if (energyDisksCollected == 3)
|
||||||
|
{
|
||||||
|
speedMultiplier = 2f;
|
||||||
|
jumpMultiplier = 2f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.gameObject.layer == 14) // Ennemis
|
||||||
|
{
|
||||||
|
life -= 2; // Réduit la vie
|
||||||
|
Debug.Log("Vie réduite : " + life);
|
||||||
|
Destroy(other.gameObject);
|
||||||
|
StartCoroutine(InvincibilityDelay());
|
||||||
|
|
||||||
|
if (life <= 0)
|
||||||
|
{
|
||||||
|
TriggerGameOver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.tag == "Exit")
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("scene1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LaunchRocket()
|
||||||
|
{
|
||||||
|
GameObject rocket = Instantiate(fusee, transform.position, transform.rotation);
|
||||||
|
Rigidbody rocketRigidbody = rocket.GetComponent<Rigidbody>();
|
||||||
|
|
||||||
|
rocketRigidbody.velocity = new Vector3(20, rocketRigidbody.velocity.y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TriggerGameOver()
|
||||||
|
{
|
||||||
|
if (uiManager != null)
|
||||||
|
{
|
||||||
|
uiManager.TriggerGameOver();
|
||||||
|
}
|
||||||
|
Debug.Log("Game Over");
|
||||||
|
}
|
||||||
|
}
|
35
FallDetector.cs
Normal file
35
FallDetector.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class FallDetector : MonoBehaviour
|
||||||
|
{
|
||||||
|
private UIManager uiManager;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// Récupère la référence du UIManager dans la scène
|
||||||
|
uiManager = FindObjectOfType<UIManager>();
|
||||||
|
if (uiManager == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("UIManager not found in the scene!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
// Assurez-vous que l'objet détecté est le droïde
|
||||||
|
Debug.Log("Collision detected with: " + other.gameObject.name);
|
||||||
|
|
||||||
|
if (other.CompareTag("Player"))
|
||||||
|
{
|
||||||
|
Debug.Log("Player detected - Triggering game over");
|
||||||
|
if (uiManager != null)
|
||||||
|
{
|
||||||
|
uiManager.TriggerGameOver();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("UIManager reference is null!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
Meteor.cs
Normal file
19
Meteor.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Meteor : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float fallSpeed = 2f; // Vitesse de chute
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
// Déplace la météorite uniquement vers le bas
|
||||||
|
transform.position += Vector3.down * fallSpeed * Time.deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCollisionEnter(Collision collision)
|
||||||
|
{
|
||||||
|
// Détruit l'objet touché
|
||||||
|
Debug.Log($"{collision.gameObject.name} destroyed by Meteorite!");
|
||||||
|
Destroy(collision.gameObject);
|
||||||
|
}
|
||||||
|
}
|
36
MeteorRain.cs
Normal file
36
MeteorRain.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class MeteorRain : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GameObject meteorPrefab; // Préfab pour les météorites
|
||||||
|
|
||||||
|
// Coroutine qui crée une météorite toutes les 3 secondes
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user