Bonjour, je croie être dans la bonne section car j'utilise Unity mais je programme en C#.
J'ai un problème que je n'arrive pas à résoudre. Je crée un jeu auquel chaque fois que le personnage tue un mob il gagne 100 points. Mais lorsqu'il meurt il reprend à 0
Se que je voudrai faire est que lorsque le personnage dépasse les 10 000 points puis lorsqu'il sera mort, il passe au niveau suivant. Mais si il meurt sans avoir dépasser les 10 000 points il recommence le même niveau.
Voila se que j'ai déjà mis dans Remover.cs
Remover.cs
Et Score.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 using UnityEngine; using System.Collections; public class Remover : MonoBehaviour { public GameObject splash; private Score score; // Reference to the Score script. void OnTriggerEnter2D(Collider2D col) { // If the player hits if(col.gameObject.tag == "Player") { // stop the camera tracking the player GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>().enabled = false; if(GameObject.FindGameObjectWithTag("HealthBar").activeSelf) { GameObject.FindGameObjectWithTag("HealthBar").SetActive(false); } Instantiate(splash, col.transform.position, transform.rotation); Destroy (col.gameObject); // Setting up the reference. score = GetComponent<Score>(); // If score >= 10000 ... if (score >= 10000) { //... Go to next level. if( Application.loadedLevel + 1 < Application.levelCount ) Application.LoadLevel( Application.loadedLevel + 1 ); } //... Restart Game. else { StartCoroutine("ReloadGame"); } } else { // ... instantiate the splash where the enemy falls in. Instantiate(splash, col.transform.position, transform.rotation); // Destroy the enemy. Destroy (col.gameObject); } } IEnumerator ReloadGame() { // ... pause briefly yield return new WaitForSeconds(2); // ... and then reload the level. Application.LoadLevel(Application.loadedLevel); } }
Lorsque je fait ça j’obtiens une erreur dans Unity :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 using UnityEngine; using System.Collections; public class Score : MonoBehaviour { public int score = 0; // The player's score. private PlayerControl playerControl; // Reference to the player control script. private int previousScore = 0; // The score in the previous frame. void Awake () { // Setting up the reference. playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>(); } void Update () { // Set the score text. guiText.text = "Score: " + score; // If the score has changed... if(previousScore != score) playerControl.StartCoroutine(playerControl.Taunt()); previousScore = score; } }
Assets/Scripts/Remover.cs(30,29): error CS0019: Operator `>=' cannot be applied to operands of type `Score' and `int'
Je ne suis pas très fort en C#.
Partager