Je viens vous demandez de l'aide car je suis bloqué
Je fais un jeu vidéo 2D mobile (C#) et je suis a la recherche de la façon d'ajouté un événement
(ex: activation d'une porte a partir de score >= 15 && score <=20)
le problème c'est que je n'arrive pas a créer de boucles, tout les temps de scores la porte s'active...
Je vous montre le code en entier pour mieux comprendre haha
si quelqu'un a une solution sil vous plait, ça serait super
Merci
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreScript : MonoBehaviour
{
public static ScoreScript instance;
public static int score, highScore;
public Text scoreText, highScoreText, gameOverScoreText;
public GameObject Porte;
public GameObject FireBlast;
public GameObject Shark;
public GameObject Bag;
public GameObject MonsterSpawn4;
public GameObject SkullAlert;
private void Awake()
{
instance = this;
if (PlayerPrefs.HasKey("HighScore"))
{
highScore = PlayerPrefs.GetInt("HighScore");
highScoreText.text = highScore.ToString();
}
}
// Start is called before the first frame update
void Start()
{
Porte.SetActive(false);
FireBlast.SetActive(false);
MonsterSpawn4.SetActive(false);
SkullAlert.SetActive(false);
}
public void AddScore()
{
score++;
UpdateHighScore();
scoreText.text = score.ToString();
gameOverScoreText.text = score.ToString();
}
public void UpdateHighScore()
{
if (score > highScore)
{
highScore = score;
highScoreText.text = highScore.ToString();
PlayerPrefs.SetInt("HighScore", highScore);
}
}
public void ResetScore()
{
score = 0;
scoreText.text = score.ToString();
gameOverScoreText.text = score.ToString();
}
public void ClearHighScore()
{
PlayerPrefs.DeleteKey("HighScore");
highScore = 0;
highScoreText.text = highScore.ToString();
}
void Update()
{
if (score >= 15f && score <= 40f || score >= 60f && score <= 80f || score >= 100f && score <= 110f || score >= 200f && score <= 210f || score >= 500f && score <= 520f)
{
Porte.SetActive(true);
}
if (score >= 15f && score <= 30f || score >= 40f && score <= 55f || score >= 70f && score <= 90f || score >= 110f && score <= 120f || score >= 150f && score <= 170f)
{
FireBlast.SetActive(true);
if(score > 30f && score < 40f || score > 55f && score < 70)
{
FireBlast.SetActive(false);
}
}
//MONSTER SPAWNER 4
if (score >= 15f && score <= 35f || score >= 50f && score <= 100f || score >= 120f && score <= 1000f)
{
Shark.SetActive(true);
MonsterSpawn4.SetActive(true);
}
if (score >= 12f && score <= 40f || score >= 60f && score <= 100f || score >= 120f && score <= 1000f)
{
Bag.SetActive(true);
MonsterSpawn4.SetActive(true);
}
//MONSTER SPAWNER FIN
if (score >= 12f && score <= 25f)
{
SkullAlert.SetActive(true);
if (score > 17f)
{
SkullAlert.SetActive(false);
}
}
}
}