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

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

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

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

Q&A

解決済

1回答

1134閲覧

Unity2D アニメクリップから別のアニメクリップに移動するためのスクリプトが知りたい

退会済みユーザー

退会済みユーザー

総合スコア0

C#

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

0グッド

0クリップ

投稿2019/03/29 05:41

編集2019/03/29 05:59

提示画像の通りjump → jump_top → jump_downへと動作させたいのですがNormalからjump(アニメクリップ)への移動はできるのですが
参考書を見てもやり方が記載しておらず調べてもNomral → jumpの場合しか記事が出てこないので
初歩的なことですがクリップからクリップの場合のスクリプトの書き方を教えてくれますでしょうか?

イメージ説明

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class PlayerController : MonoBehaviour { 6 7 enum jump_state 8 { 9 ground, 10 jump_start, 11 jump_up, 12 jump_down, 13 14 } 15 16 jump_state isJump;//ジャンプ管理 17 private int rfriction;//摩擦判定 18 public float JumpForce;//ジャンプ数値 19 public float max_speed;//最大速度 20 public float speedForce;//移動速度 21 private float speedx;//速度の絶対値 22 private float anispeed = 20.0f;//アニメーション速度 23 private int key;//キー判定 24 private int prekey;//逆摩擦判定 25 26 private Vector2 v = new Vector2(0.50f, 1);//摩擦係数 27 private Vector2 v2 = new Vector2(0.98f, 1f); 28 29 private Animator animator; 30 private Rigidbody2D rb; 31 32 33 [SerializeField] ContactFilter2D filter2d; 34 35 36 37 // Use this for initialization 38 void Start () { 39 40 rb = GetComponent<Rigidbody2D>(); 41 animator = GetComponent<Animator>(); 42// animator.SetBool("Normal",true); 43 key = 0; 44 prekey = 0; 45 isJump = jump_state.ground; 46 47 rfriction = 0; 48 } 49 50 51 52 53 54 //Rigidbodyはここに書く 55 void FixedUpdate() 56 { 57 58 /*移動処理*/ 59 //右入力→ 60 if (key == 1) 61 { 62 //animator.SetBool("Run", true); 63 64 if (speedx < max_speed) 65 { 66 animator.SetBool("Run",true); 67 rb.AddForce( 68 transform.right * key * speedForce); 69 } 70 animator.speed = speedx / anispeed; 71 } 72 73 //←左入力 74 if (key == -1) 75 { 76// animator.SetBool("Run", true); 77 78 if (speedx < max_speed) 79 { 80 animator.SetBool("Run", true); 81 82 rb.AddForce( 83 transform.right * key * speedForce); 84 } 85 86 animator.speed = speedx / anispeed; 87 } 88 89 //ジャンプ 90 if(isJump == jump_state.jump_start) 91 { 92 animator.SetBool("Jump",true); 93 94 Vector2 v2 = new Vector2(key * speedForce, JumpForce); 95 Vector2 v3; 96 if (speedx > 0) 97 { 98 v3 = new Vector2(key * speedForce, JumpForce + (speedx * 4.0f)); 99 rb.AddForce(v3); 100 101 } 102 103 if (speedx == 0) 104 { 105 v2 = new Vector2(key * speedForce, JumpForce); 106 rb.AddForce(v2); 107 } 108 isJump = jump_state.jump_up; 109 } 110 111 //ジャンプモーション速度を調整 112 if(rb.velocity.y > 0 && isJump == jump_state.jump_up) 113 { 114 //Debug.Log("aaaaa"); 115 116 float speedy = Mathf.Abs(rb.velocity.y); 117 animator.speed = speedy/ 20.0f; 118 } 119 120 if(isJump == jump_state.jump_up && key != 0)//ジャンプ中で左右に動いているときの摩擦調整 121 { 122 123 if (speedx < max_speed) 124 { 125 126 rb.AddForce( 127 transform.right * key * speedForce / 20); 128 } 129 130 //Vector2 k1 = new Vector2(speedForce * key,1); 131 //rb.AddForce(k1); 132 133 } 134 135 /*AddForce()の摩擦を調整 ジャンプ中に左右キーを押して離したとき*/ 136 if ((speedx > 0) && (key == 0) && isJump == jump_state.jump_up) 137 { 138 Debug.Log("aaaaaa"); 139 Vector2 vtemp = new Vector2(0.99f,1); 140 rb.velocity *= vtemp; 141 142 } 143 144 /*AddForce()の摩擦を調整*/ 145 if ( (speedx > 0) && (key == 0) && isJump == jump_state.ground ) 146 { 147 //→ 148 if (rb.velocity.x > 0 ) 149 { 150 if (rb.velocity.x < 0.000000000000000000000000000000000000001f) 151 { 152// Debug.Log("プラス→"); 153 rb.velocity = Vector2.zero; 154 } 155 } 156 157 //← 158 if (rb.velocity.x < 0 ) 159 { 160 if (rb.velocity.x > - 0.000000000000000000000000000000000001f) 161 { 162// Debug.Log("マイナス←"); 163 rb.velocity = Vector2.zero; 164 } 165 } 166 rb.velocity *= v; 167 } 168 169 170 //移動中に逆キーを押したときの摩擦軽減処理 ← 171 if (rfriction == -1) 172 { 173 rb.velocity *= v2; 174 175 } 176 177 if (speedx == 0.0) 178 { 179 rfriction = 0; 180 } 181 182 //移動中に逆キーを押したときの摩擦軽減処理 → 183 if (rfriction == 1) 184 { 185 Debug.Log("→"); 186 rb.velocity *= v2; 187 } 188 189 speedx = Mathf.Abs(rb.velocity.x);//移動速度 190 191 192 193 //地面チェック 194 if (rb.IsTouching(filter2d)) 195 { 196 isJump = jump_state.ground; 197 } 198 } 199 200 /*Update*/ 201 //Input系はここに書く 202 void Update () { 203 204 Move(); 205 } 206 207 private void Move() 208 { 209 key = 0; 210 211 212 if (Input.GetKey(KeyCode.Space) && isJump == jump_state.ground)//スペースキージャンプ入力 213 { 214 isJump = jump_state.jump_start; 215 } 216 217 if (isJump == jump_state.ground)//ジャンプしてないときはジャンプモーションを消す。 218 { 219 //animator.SetBool("Jump_down", false); 220 221 222 animator.SetBool("Jump", false); 223 animator.SetBool("Jump_down", false); 224 animator.SetBool("Jump_top", false); 225 226 } 227 228 if (Input.GetKey(KeyCode.RightArrow))//右キー入力 229 { 230 if(rb.velocity.x > 0) 231 { 232 prekey = -1; 233 } 234 235 key = 1; 236 } 237 238 if (Input.GetKey(KeyCode.LeftArrow))//左キー入力 239 { 240 if(rb.velocity.x < 0) 241 { 242 prekey = 1; 243 } 244 245 key = -1; 246 } 247 248 /*摩擦軽減処理*/ 249 //摩擦軽減の向き← 250 if(Input.GetKey(KeyCode.LeftArrow) && key == prekey) 251 { 252 rfriction = -1;//逆キーを押したときの摩擦 253 } 254 255 //摩擦軽減の向き→ 256 if (Input.GetKey(KeyCode.RightArrow) && key == prekey) 257 { 258 rfriction = 1; 259 } 260 261 if (isJump == jump_state.ground) 262 { 263 // Debug.Log("aaaaa"); 264 animator.SetBool("Jump", false); 265 } 266 267 if (key == 0 && speedx == 0) 268 { 269 animator.SetBool("Run", false); 270 } 271 272 //ジャンプしてる時はRUNモーションを解除 273 if (isJump == jump_state.jump_up) 274 { 275 276 animator.SetBool("Run", false); 277 278 } 279 280 281 282 if (key != 0)//左右向き修正 283 { 284 transform.localScale = new Vector3(key, 1, 1); 285 } 286 287 288 // Debug.Log(rb.velocity.y); 289 //待機モーション時のモーション速度(デフォルト) 290 if(isJump == jump_state.ground && speedx == 0 ) 291 { 292 animator.speed = 1; 293 } 294 295 } 296 297 298 299 private void OnCollisionEnter2D(Collision2D co) 300 { 301 302 } 303}

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

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

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

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

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

guest

回答1

0

ベストアンサー

__jump_top__でのアニメーションクリップは
空中攻撃など、なにか使うのでしょうか?
使わない場合、必要ないと思われます。
Jump->Jump_down->Normal
のように推移してみてはどうでしょうか?

投稿2019/04/05 05:23

Gurumer

総合スコア33

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.51%

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

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

質問する

関連した質問