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

回答編集履歴

3

スペルミス

2017/02/13 03:57

投稿

turbgraphics200
turbgraphics200

スコア4269

answer CHANGED
@@ -6,7 +6,7 @@
6
6
  // 現在どのステップかを保持
7
7
  int step = 0;
8
8
  //あとステップごとのスプライトを配列として保持
9
- Splite[] stepSplites = new Sprite[] {nomalSplite, superSplite, hyperSplite};
9
+ Sprite[] stepSplites = new Sprite[] {nomalSplite, superSplite, hyperSplite};
10
10
 
11
11
  void OnTriggerExit2D(Collider2D other) {
12
12
  if(other.tag == "item") step = Math.Min(1, step + 1); // アイテムならステップを増やす(Max 1)

2

てきにあ立った場合段階的に減らすのに対応。あとMin Max 対応

2017/02/13 03:57

投稿

turbgraphics200
turbgraphics200

スコア4269

answer CHANGED
@@ -1,5 +1,5 @@
1
1
  コメントだとコード見づらくなるため回答に書きますが
2
- つまり、アイテムをとるたびにパワーアップするが、敵に当たるとリセットつまり初期の状態戻るという感じと理解したけど間違ってたらゴメン。
2
+ つまり、アイテムをとるたびにパワーアップするが、敵に当たると段階的にパワーダウさせる
3
3
  ステップを保持するものと各ステップごとのスプライトをクラスのメンバ変数として用意して、あとは、ステップと配列からMainSpriteRenderer.spriteにスプライトを設定する。
4
4
  ```c#
5
5
  public class Player : MonoBehaviour {
@@ -9,8 +9,8 @@
9
9
  Splite[] stepSplites = new Sprite[] {nomalSplite, superSplite, hyperSplite};
10
10
 
11
11
  void OnTriggerExit2D(Collider2D other) {
12
- if(other.tag == "item") step++; // アイテムならステップを増やす
12
+ if(other.tag == "item") step = Math.Min(1, step + 1); // アイテムならステップを増やす(Max 1)
13
- else if(other.tag == "Enemy") step = 0; // 敵に当たればリセ
13
+ else if(other.tag == "Enemy") step = Math.Max(0, step - 1); // 敵に当たれば逆にステプを減らす(Min 0)
14
14
  MainSpriteRenderer.sprite = stepSplites[step]; // ステップのスプライトを適用
15
15
  }
16
16
  }

1

クラスのメンバー変数定義は型をちゃんと指定しないとだめ

2017/02/13 03:55

投稿

turbgraphics200
turbgraphics200

スコア4269

answer CHANGED
@@ -4,9 +4,9 @@
4
4
  ```c#
5
5
  public class Player : MonoBehaviour {
6
6
  // 現在どのステップかを保持
7
- var step = 0;
7
+ int step = 0;
8
8
  //あとステップごとのスプライトを配列として保持
9
- var stepSplites = new Sprite[] {nomalSplite, superSplite, hyperSplite};
9
+ Splite[] stepSplites = new Sprite[] {nomalSplite, superSplite, hyperSplite};
10
10
 
11
11
  void OnTriggerExit2D(Collider2D other) {
12
12
  if(other.tag == "item") step++; // アイテムならステップを増やす