J'ai un problème quand mon personnage perd ses points de vie la scène se charge à un endroit précis, ce qui fonctionne mais quand je recommence mon jeu depuis le début la scène (1) qui a ce code se lance à partir du point où j'ai fait le gameOver
et j'ai remarqué que j'ai un journal de non compatibilité de Unity pour ce code
Voici donc le code du game over
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 private Transform SpawnOutLocation; void Start () { SpawnOutLocation = this.gameObject.transform.GetChild (0); } public void Update () { if (life_point <= 0) { SceneManager.LoadScene (1); SpawnManager.SharedInstance.SetSpawn (SpawnOutLocation.position); } }
et voici le code de base qui fait tout cela
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
58
59
60
61
62
63
64
65
66
67 public static SpawnManager SharedInstance { get ; private set ;} public GameObject DefaultPlayer; private Transform defaultPoint; private Vector3 spawnlocation; private bool SetPoint; private void Awake () { SceneManager.sceneLoaded += OnLevelWasLoaded; if (SharedInstance == null) { SharedInstance = this; Destroy (gameObject); } else Destroy (gameObject); } public void SetSpawn (Vector3 x){ SetPoint = true; spawnlocation = x; } private void OnLevelWasLoaded (Scene scene , LoadSceneMode mode ){ print (spawnlocation); if (mode > 0) { Transform temp = GameObject.Find ("PointafterGameover").transform; Instantiate (DefaultPlayer, temp.position, Quaternion.identity); } if (mode == 0) { if (!SetPoint) { spawnAtStart (); } else { spawnAtSetlocation (); } } } void spawnAtSetlocation (){ Instantiate (DefaultPlayer, spawnlocation, Quaternion.identity); SetPoint = false; } void spawnAtStart (){ defaultPoint = GameObject.Find ("PointafterGameover").transform; DefaultPlayer.transform.position = defaultPoint.transform.position; } public void spawnNewGames (){ defaultPoint = GameObject.Find ("DefaultPoint").transform; DefaultPlayer.transform.position = defaultPoint.transform.position; }
Partager