質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Q&A

1回答

1312閲覧

シーン管理のやり方について

srp479

総合スコア4

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

0グッド

0クリップ

投稿2019/10/03 01:52

今キー入力でシーン移動なのですが
Enemyを倒したらクリアにしたいです
どのようにしたらいいのでしょう
宜しければ知恵をお貸しください

public

1 { 2 if (Keyboard.GetState().IsKeyDown(Keys.Space)) 3 { 4 this.isEnd = true; 5 6 } 7 } 8 9class Enemy2 : Character 10 { 11 private Vector2 velocity; 12 13 14 public static int Length { get; internal set; } 15 16 17 public Enemy2(Vector2 position) 18 : base("敵", new Vector2(150f, 350.0f), 32.0f) 19 { 20 21 } 22 23 24 public override void Update() 25 { 26 velocity = Vector2.Zero; 27 position = new Vector2( 28 rnd.Next(Screen.Width - 64), 29 (Screen.Height - 64)); 30 velocity = new Vector2(-10f, -450f); 31 32 33 34 35 36 37 if (position.X < 0) 38 { 39 velocity = -velocity; 40 41 42 } 43 else if (position.X >= Screen.Width - 64) 44 { 45 velocity = -velocity; 46 47 48 } 49 position += velocity; 50 var min = new Vector2(radius, radius); 51 var max = new Vector2(828.0f - 100.0f, 792.0f - 100.0f); 52 position = Vector2.Clamp(position, min, max); 53 54 } 55 public override void Hit(Character character) 56 { 57 if (character is Bullet || character is Player) 58 { 59 isDead = true; 60 } 61 62 63 64 } 65 public override Character New() 66 { 67 return null; 68 } 69 } 70 71 class Enemy : Character 72 { 73 private Vector2 velocity; 74 75 76 public static int Length { get; internal set; } 77 public static object PlayerPos { get; internal set; } 78 79 public Enemy(Vector2 position) 80 : base("敵", new Vector2(350f, 50.0f), 32.0f) 81 { 82 83 } 84 85 86 public override void Update() 87 { 88 velocity = Vector2.Zero; 89 position = new Vector2( 90 rnd.Next(Screen.Width - 64), 91 (Screen.Height - 64)); 92 velocity = new Vector2(-110f, -650f); 93 94 95 96 97 98 99 100 101 if (position.X < 0) 102 { 103 velocity = -velocity; 104 105 106 } 107 else if (position.X >= Screen.Width - 64) 108 { 109 velocity = -velocity; 110 111 112 } 113 position += velocity; 114 var min = new Vector2(radius, radius); 115 var max = new Vector2(828.0f - 100.0f, 792.0f - 100.0f); 116 position = Vector2.Clamp(position, min, max); 117 118 } 119 public override void Hit(Character character) 120 { 121 if (character is Bullet || character is Player) 122 { 123 isDead = true; 124 125 } 126 127 128 } 129 public override Character New() 130 { 131 return null; 132 } 133 } 134 135コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2019/10/03 02:09

なにをクリアにするんでしょうか また、提示のコードの説明も付けましょう
guest

回答1

0

クリア後のシーンは別に用意されているという解釈で説明します。(用意していないならCeateSceneで作成し、保存してください。)

File.BuildSettingsの上部[写真1]に作成したシーン(プロジェクトのAssets.Scenesというところにあると思います。なかったらエクスプローラーで".unity"を検索してみてください)を全てドラッグ&ドロップし、全てのチェックボックスをONにします。

Enemyのインスタンスを作成するメソッドのあるクラスのUpdateメソッドに

C#

1Update() 2{ 3 bool isEnd = true; 4 foreach(var item in /*Enemyのインスタンスの配列*/) 5 { 6 isEnd = isEnd & item.isDead 7 } 8 9 if (isEnd) SceneManager.LoadScene(/*クリアシーンの名前*/); 10}

と追加すればおそらく意図した動きとなるのではないでしょうか?

写真1:

写真1

投稿2019/10/06 00:57

KanazawaKureha

総合スコア368

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問