teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの追加

2020/02/13 21:58

投稿

tetsunosuke0320
tetsunosuke0320

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,14 +1,322 @@
1
+ ```c```ここに言語を入力
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using UnityEngine;
5
+ using UnityEngine.UI;
6
+ public class boost:MonoBehaviour
7
+ {
8
+ public GameObject score_object = null;
9
+ public GameObject bulletPrefab;
10
+ public float shotSpeed;
11
+ public int shotCount = 30;
12
+ private float shotInterval;
13
+
14
+ void Update()
15
+ {
16
+ if (Input.GetKey(KeyCode.Space ))
17
+ {
18
+
19
+ shotInterval += 1;
20
+
21
+ if (shotInterval % 5 == 0 && shotCount > 0)
22
+ {
23
+ shotCount -= 1;
24
+
25
+ GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.Euler(transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
26
+ Rigidbody bulletRb = bullet.GetComponent<Rigidbody>();
27
+ bulletRb.AddForce(transform.forward * shotSpeed);
28
+
29
+ //射撃されてから3秒後に銃弾のオブジェクトを破壊する.
30
+
31
+ Destroy(bullet, 0.2f);
32
+ }
33
+
34
+ }
35
+ else if (Input.GetKeyDown(KeyCode.R))
36
+ {
37
+ shotCount = 300;
38
+
39
+ }
40
+ Text score_text = score_object.GetComponent<Text>();
41
+ // テキストの表示を入れ替える
42
+ score_text.text = "fuel" + shotCount;
43
+
44
+
45
+
46
+ }
47
+ }
48
+ ```
49
+ ```c
50
+ using System.Collections;
51
+ using System.Collections.Generic;
52
+ using UnityEngine;
53
+ using UnityEngine.AI;
54
+
55
+ public class Chase : MonoBehaviour
56
+ {
57
+ public GameObject target;
58
+ private NavMeshAgent agent;
59
+
60
+ void Start()
61
+ {
62
+ agent = GetComponent<NavMeshAgent>();
63
+ }
64
+
65
+ void Update()
66
+ {
67
+ // ターゲットの位置を目的地に設定する。
68
+ agent.destination = target.transform.position;
69
+ }
70
+ }
71
+
72
+ c
73
+ using System.Collections;
74
+ using System.Collections.Generic;
75
+ using UnityEngine;
76
+ using System.Collections;
77
+
78
+ public class oto : MonoBehaviour
79
+ {
80
+ private AudioSource sound01;
81
+ private AudioSource sound02;
82
+ void Start()
83
+ {
84
+ //AudioSourceコンポーネントを取得し、変数に格納
85
+ AudioSource[] audioSources = GetComponents<AudioSource>();
86
+ sound01 = audioSources[0];
87
+ }
88
+
89
+ void Update()
90
+ {
91
+ //指定のキーが押されたら音声ファイル再生
92
+ if (Input.GetKey(KeyCode.Mouse0))
93
+ {
94
+ sound01.PlayOneShot(sound01.clip);
95
+ }
96
+ if (Input.GetKey(KeyCode.Space))
97
+ {
98
+ sound02.PlayOneShot(sound02.clip);
99
+ }
100
+ }
101
+ }
102
+
103
+
104
+ c
105
+ using System.Collections;
106
+ using System.Collections.Generic;
107
+ using UnityEngine;
108
+ using System.Collections;
109
+
110
+ public class oto2 : MonoBehaviour
111
+ {
112
+ private AudioSource sound01;
113
+
114
+ void Start()
115
+ {
116
+ //AudioSourceコンポーネントを取得し、変数に格納
117
+ sound01 = GetComponent<AudioSource>();
118
+ }
119
+
120
+ void Update()
121
+ {
122
+ //指定のキーが押されたら音声ファイル再生
123
+ if (Input.GetKey(KeyCode.Space))
124
+ {
125
+ sound01.PlayOneShot(sound01.clip);
126
+ }
127
+ }
128
+
129
+ c
130
+ using System.Collections;
131
+ using System.Collections.Generic;
132
+ using UnityEngine;
133
+
134
+ public class Seisei : MonoBehaviour
135
+ {
136
+ // 出現させる敵を入れておく
137
+ [SerializeField] GameObject[] enemys;
138
+ // 次に敵が出現するまでの時間
139
+ [SerializeField] float appearNextTime;
140
+ // この場所から出現する敵の数
141
+ [SerializeField] int maxNumOfEnemys;
142
+ // 今何人の敵を出現させたか(総数)
143
+ private int numberOfEnemys;
144
+ // 待ち時間計測フィールド
145
+ private float elapsedTime;
146
+
147
+ // Use this for initialization
148
+ void Start()
149
+ {
150
+ numberOfEnemys = 0;
151
+ elapsedTime = 0f;
152
+ }
153
+ void Update()
154
+ {
155
+ // この場所から出現する最大数を超えてたら何もしない
156
+ if (numberOfEnemys >= maxNumOfEnemys)
157
+ {
158
+ return;
159
+ }
160
+ // 経過時間を足す
161
+ elapsedTime += Time.deltaTime;
162
+
163
+ // 経過時間が経ったら
164
+ if (elapsedTime > appearNextTime)
165
+ {
166
+ elapsedTime = 0f;
167
+
168
+ AppearEnemy();
169
+ }
170
+ }
171
+ void AppearEnemy()
172
+ {
173
+ // 出現させる敵をランダムに選ぶ
174
+ var randomValue = Random.Range(0, enemys.Length);
175
+ // 敵の向きをランダムに決定
176
+ var randomRotationY = Random.value * 360f;
177
+
178
+ GameObject.Instantiate(enemys[randomValue], transform.position, Quaternion.Euler(0f, randomRotationY, 0f));
179
+
180
+ numberOfEnemys++;
181
+ elapsedTime = 0f;
182
+ }
183
+ }
184
+
185
+ c
186
+ using System.Collections;
187
+ using System.Collections.Generic;
188
+ using UnityEngine;
189
+ using UnityEngine.UI;
190
+ public class Shooting : MonoBehaviour
191
+ {
192
+ public GameObject score_object = null;
193
+ public GameObject bulletPrefab;
194
+ public float shotSpeed;
195
+ public int shotCount = 30;
196
+ private float shotInterval;
197
+ public Explosion m_explosionPrefab;
198
+ public AudioClip audioClip1;
199
+ private AudioSource audioSource;
200
+
201
+ void Update()
202
+ {
203
+ if (Input.GetKey(KeyCode.Mouse0))
204
+ {
205
+
206
+ shotInterval += 1;
207
+
208
+ if (shotInterval % 5 == 0 && shotCount > 0)
209
+ {
210
+ shotCount -= 1;
211
+
212
+ GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.Euler(transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
213
+ Rigidbody bulletRb = bullet.GetComponent<Rigidbody>();
214
+ bulletRb.AddForce(transform.forward * shotSpeed);
215
+
216
+ //射撃されてから3秒後に銃弾のオブジェクトを破壊する.
217
+
218
+ Destroy(bullet, 3.0f);
219
+
220
+ }
221
+
222
+ }
223
+ else if (Input.GetKeyDown(KeyCode.R))
224
+ {
225
+ shotCount = 30;
226
+
227
+ }
228
+ Text score_text = score_object.GetComponent<Text>();
229
+ // テキストの表示を入れ替える
230
+ score_text.text = "bullet" + shotCount;
231
+
232
+
233
+
234
+ }
235
+ }
236
+
237
+ c
238
+ using System.Collections;
239
+ using System.Collections.Generic;
240
+ using UnityEngine;
241
+ using UnityEngine.SceneManagement;
242
+
243
+ public class teki : MonoBehaviour
244
+ {
245
+ // Start is called before the first frame update
246
+ void Start()
247
+ {
248
+
249
+ }
250
+ void OnTriggerEnter(Collider other)
251
+ {
252
+
253
+ //ぶつかったオブジェクトのTagにShellという名前が書いてあったならば(条件).
254
+ if (other.CompareTag("teki"))
255
+ {
256
+
257
+ //HPクラスのDamage関数を呼び出す
258
+
259
+
260
+ //ぶつかってきたオブジェクトを破壊する.
261
+ SceneManager.LoadScene("result");
262
+ }
263
+ }
264
+
265
+ }
266
+ c
267
+ using System.Collections;
268
+ using System.Collections.Generic;
269
+ using UnityEngine;
270
+
271
+ public class Explosion : MonoBehaviour
272
+ {
273
+ private void Start()
274
+ {
275
+ // 演出が完了したら削除する
276
+ var particleSystem = GetComponent<ParticleSystem>();
277
+ Destroy(gameObject, particleSystem.main.duration);
278
+ }
279
+
280
+ }
281
+ c
282
+ using System.Collections;
283
+ using System.Collections.Generic;
284
+ using UnityEngine;
285
+
286
+
287
+ public class bakuhatsu : MonoBehaviour
288
+ {
289
+ private AudioSource audioSource;
290
+ public AudioClip audioClip1;
291
+ public Explosion m_explosionPrefab;
292
+ // Start is called before the first frame update
293
+ void Start()
294
+ {
295
+
296
+ }
297
+
298
+ // Update is called once per frame
299
+ void Update()
300
+ {if (Input.GetKey(KeyCode.Mouse0)) ;
301
+ Instantiate(
302
+ m_explosionPrefab,
303
+ transform.localPosition,
304
+ Quaternion.identity);
305
+ audioSource = gameObject.GetComponent<AudioSource>();
306
+ audioSource.clip = audioClip1;
307
+ audioSource.Play();
308
+
309
+ }
310
+ }
311
+
312
+ ```
313
+ ```
1
- unityでc#でゲームを作っているのですが、先ほどunityのパッケージをインポートして再生しよう
314
+ ```unityでc#でfpsゲームを作っているのですが、先ほどunityのパッケージをインポートして再生しよう
2
315
  としたら
3
316
  (1) Library\PackageCache\com.unity.postprocessing@2.0.3-preview\PostProcessing\Runtime\PostProcessManager.cs(424,66): error CS0117: 'EditorSceneManager' does not contain a definition for 'IsGameObjectInScene'
4
317
 
5
318
  (2)  Library\PackageCache\com.unity.postprocessing@2.0.3-preview\PostProcessing\Runtime\PostProcessManager.cs(425,66): error CS0117: 'EditorSceneManager' does not contain a definition for 'IsGameObjectInMainScenes'
6
319
 
7
- (3)  PlayerSettings Validation: Requested build target group (20) doesn't exist; #define symbols for scripting won't be added.
8
- UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
9
- UnityStandardAssets.CrossPlatformInput.Inspector.CrossPlatformInitialize:SetEnabled(String, Boolean, Boolean) (at Assets/Standard Assets/Editor/CrossPlatformInput/CrossPlatformInputInitialize.cs:127)
10
- UnityStandardAssets.CrossPlatformInput.Inspector.CrossPlatformInitialize:.cctor() (at Assets/Standard Assets/Editor/CrossPlatformInput/CrossPlatformInputInitialize.cs:22)
11
- UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[])
12
320
 
13
321
  と出てきてしまいます。初心者なのでよくわかりません。なので
14
322
  1 解決策