質問編集履歴
1
GameManagerのスクリプトを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,4 +67,96 @@
|
|
67
67
|
inputField.ActivateInputField();
|
68
68
|
}
|
69
69
|
}
|
70
|
+
```
|
71
|
+
|
72
|
+
```c#
|
73
|
+
using System.Collections;
|
74
|
+
using System.Collections.Generic;
|
75
|
+
using UnityEngine;
|
76
|
+
|
77
|
+
public class GManager : MonoBehaviour
|
78
|
+
{
|
79
|
+
public static GManager instance = null;
|
80
|
+
|
81
|
+
[Header("スコア")]public int score;
|
82
|
+
[Header("現在のスコア")]public int stageNum;
|
83
|
+
[Header("現在の復帰位置")]public int continueNum;
|
84
|
+
[Header("現在の残機")]public int heartNum;
|
85
|
+
[Header("デフォルトの残機")]public int defaultHeartNum;
|
86
|
+
[HideInInspector]public bool isGameOver = false;
|
87
|
+
|
88
|
+
private AudioSource audioSource = null;
|
89
|
+
|
90
|
+
private void Awake()
|
91
|
+
{
|
92
|
+
if(instance == null)
|
93
|
+
{
|
94
|
+
instance = this;
|
95
|
+
DontDestroyOnLoad(this.gameObject);
|
96
|
+
}
|
97
|
+
else
|
98
|
+
{
|
99
|
+
Destroy(this.gameObject);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
private void Start()
|
104
|
+
{
|
105
|
+
audioSource = GetComponent<AudioSource>();
|
106
|
+
}
|
107
|
+
|
108
|
+
///<summary>
|
109
|
+
///残機を1つ増やす
|
110
|
+
///</summary>
|
111
|
+
public void AddHeartNum()
|
112
|
+
{
|
113
|
+
if(heartNum < 99)
|
114
|
+
{
|
115
|
+
++heartNum;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
///<summary>
|
120
|
+
///残機を1つ減らす
|
121
|
+
///</summary>
|
122
|
+
public void SubHeartNum()
|
123
|
+
{
|
124
|
+
if(heartNum > 0)
|
125
|
+
{
|
126
|
+
--heartNum;
|
127
|
+
}
|
128
|
+
else
|
129
|
+
{
|
130
|
+
isGameOver = true;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
///<summary>
|
135
|
+
///最初から始める時の処理
|
136
|
+
///</summary>
|
137
|
+
public void RetryGame()
|
138
|
+
{
|
139
|
+
isGameOver = false;
|
140
|
+
heartNum = defaultHeartNum;
|
141
|
+
score = 0;
|
142
|
+
stageNum = 1;
|
143
|
+
continueNum = 0;
|
144
|
+
}
|
145
|
+
|
146
|
+
///<summary>
|
147
|
+
///SEを鳴らす
|
148
|
+
///</summary>
|
149
|
+
public void PlaySE(AudioClip clip)
|
150
|
+
{
|
151
|
+
if(audioSource != null)
|
152
|
+
{
|
153
|
+
audioSource.PlayOneShot(clip);
|
154
|
+
}
|
155
|
+
else
|
156
|
+
{
|
157
|
+
Debug.Log("オーディオソースが設定されていません");
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
コード
|
70
162
|
```
|