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

回答編集履歴

5

文法の修正

2018/07/02 10:39

投稿

退会済みユーザー
answer CHANGED
@@ -76,7 +76,6 @@
76
76
  private void Start () {
77
77
  gameObject.SetActive (true);
78
78
  rb2D = GetComponent<Rigidbody2D>();
79
- pObject.gameObject.SetActive(false);
80
79
  }
81
80
 
82
81
  void Update () {
@@ -92,11 +91,9 @@
92
91
  IEnumerator OnCollisionEnter2D (Collision2D collision) {
93
92
  gameover = true;
94
93
  GameOverGUI.SendMessage("Lose");
95
- pObject.gameObject.SetActive(true);
96
94
 
97
95
  yield return new WaitForSeconds(1f);
98
96
 
99
- pObject.gameObject.SetActive(false);
100
97
  gameObject.SetActive (false);
101
98
  while(!Input.GetMouseButtonDown(0)) { yield return 0; }
102
99
  Application.LoadLevel("TitleScene");

4

文法の修正

2018/07/02 10:39

投稿

退会済みユーザー
answer CHANGED
@@ -65,9 +65,6 @@
65
65
  using UnityEngine.SceneManagement;
66
66
 
67
67
  public class CubeController : MonoBehaviour {
68
- [SerializeField]
69
- ParticleSystem pObject;
70
- private Explodable _explodable;
71
68
  public AudioClip Point;
72
69
  private AudioSource audioSource1;
73
70
  private Rigidbody2D rb2D;
@@ -79,7 +76,6 @@
79
76
  private void Start () {
80
77
  gameObject.SetActive (true);
81
78
  rb2D = GetComponent<Rigidbody2D>();
82
- _explodable = GetComponent<Explodable>();
83
79
  pObject.gameObject.SetActive(false);
84
80
  }
85
81
 

3

文法の修正

2018/07/02 10:36

投稿

退会済みユーザー
answer CHANGED
@@ -87,12 +87,6 @@
87
87
  //gameoverフラグがtrueになった時、ジャンプできないようにする
88
88
  if (Input.GetMouseButtonDown (0) && !gameover) {
89
89
  Jump ();
90
- }
91
- if (gameover == true) {
92
- // _explodable.explode();
93
- // ExplosionForce ef = GameObject.FindObjectOfType<ExplosionForce>();
94
- // ef.doExplosion(transform.position);
95
- }
96
90
  }
97
91
 
98
92
  void Jump(){

2

文法の修正

2018/07/02 10:32

投稿

退会済みユーザー
answer CHANGED
@@ -56,4 +56,71 @@
56
56
  Application.LoadLevel("TitleScene");
57
57
  }
58
58
  }
59
- ```
59
+ ```
60
+ から
61
+ ```c#
62
+ using System.Collections;
63
+ using System.Collections.Generic;
64
+ using UnityEngine;
65
+ using UnityEngine.SceneManagement;
66
+
67
+ public class CubeController : MonoBehaviour {
68
+ [SerializeField]
69
+ ParticleSystem pObject;
70
+ private Explodable _explodable;
71
+ public AudioClip Point;
72
+ private AudioSource audioSource1;
73
+ private Rigidbody2D rb2D;
74
+ private float jumpForce = 4.0f;
75
+ public GameObject Score;
76
+ public GameObject GameOverGUI;
77
+ private bool gameover = false;
78
+
79
+ private void Start () {
80
+ gameObject.SetActive (true);
81
+ rb2D = GetComponent<Rigidbody2D>();
82
+ _explodable = GetComponent<Explodable>();
83
+ pObject.gameObject.SetActive(false);
84
+ }
85
+
86
+ void Update () {
87
+ //gameoverフラグがtrueになった時、ジャンプできないようにする
88
+ if (Input.GetMouseButtonDown (0) && !gameover) {
89
+ Jump ();
90
+ }
91
+ if (gameover == true) {
92
+ // _explodable.explode();
93
+ // ExplosionForce ef = GameObject.FindObjectOfType<ExplosionForce>();
94
+ // ef.doExplosion(transform.position);
95
+ }
96
+ }
97
+
98
+ void Jump(){
99
+ rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
100
+ }
101
+
102
+ IEnumerator OnCollisionEnter2D (Collision2D collision) {
103
+ gameover = true;
104
+ GameOverGUI.SendMessage("Lose");
105
+ pObject.gameObject.SetActive(true);
106
+
107
+ yield return new WaitForSeconds(1f);
108
+
109
+ pObject.gameObject.SetActive(false);
110
+ gameObject.SetActive (false);
111
+ while(!Input.GetMouseButtonDown(0)) { yield return 0; }
112
+ Application.LoadLevel("TitleScene");
113
+ }
114
+
115
+ void OnTriggerEnter2D (Collider2D col){
116
+ audioSource1 = gameObject.GetComponent<AudioSource> ();
117
+ audioSource1.clip = Point;
118
+ audioSource1.Play ();
119
+ //Score(GUIText)のScoreUpメソッドを呼び出す
120
+ Score.SendMessage ("ScoreUp", 1);
121
+ //何度も加点されないように削除しておく
122
+ Destroy (col.gameObject);
123
+ }
124
+ }
125
+ ```
126
+ に変更したところ直りました。

1

文法の修正

2018/07/02 10:30

投稿

退会済みユーザー
answer CHANGED
@@ -1,1 +1,59 @@
1
+ ```c#
2
+ using System.Collections;
3
+ using System.Collections.Generic;
1
- 少しコードをいじってみたら直りました。
4
+ using UnityEngine;
5
+
6
+ public class CubeController : MonoBehaviour {
7
+ public AudioClip Point;
8
+ private AudioSource audioSource1;
9
+ private Rigidbody2D rb2D;
10
+ private float jumpForce = 4.0f;
11
+ public GameObject Score;
12
+ public GameObject GameOverGUI;
13
+ private bool gameover = false;
14
+
15
+ // Use this for initialization
16
+ private void Start () {
17
+ rb2D = GetComponent<Rigidbody2D>();
18
+ }
19
+
20
+ void Update () {
21
+ //gameoverフラグがtrueになった時、ジャンプできないようにする
22
+ if(Input.GetMouseButtonDown(0) && !gameover){
23
+ Jump();
24
+ }
25
+ if(gameover == true){
26
+ //GAME OVERのGUIを表示する
27
+ GameOverGUI.SendMessage("Lose");
28
+ }
29
+ }
30
+
31
+ void Jump(){
32
+ rb2D.velocity = new Vector2(rb2D.velocity.x, jumpForce);
33
+ }
34
+
35
+ private void OnCollisionEnter2D (Collision2D collision) {
36
+ StartCoroutine(GameOver());
37
+ }
38
+
39
+ void OnTriggerEnter2D (Collider2D col){
40
+ audioSource1 = gameObject.GetComponent<AudioSource> ();
41
+ audioSource1.clip = Point;
42
+ audioSource1.Play ();
43
+ //Score(GUIText)のScoreUpメソッドを呼び出す
44
+ Score.SendMessage ("ScoreUp", 1);
45
+ //何度も加点されないように削除しておく
46
+ Destroy (col.gameObject);
47
+ }
48
+
49
+ IEnumerator GameOver() {
50
+ // ゲームオーバーのフラグをtrueにする
51
+ gameover = true;
52
+ // マウス連打してたらスコアを見る暇もなくタイトルへ戻ってしまう対策、1秒待機
53
+ yield return new WaitForSeconds(1f);
54
+ // マウスクリックしたらゲームの最初に戻る
55
+ while(!Input.GetMouseButtonDown(0)) { yield return 0; }
56
+ Application.LoadLevel("TitleScene");
57
+ }
58
+ }
59
+ ```