LoginSignup
0
0

More than 1 year has passed since last update.

Unity2DのチュートリアルをInputSystemに書き換える(3)

Posted at

EnhancedTouch

というわけでスライドで発射するように適当に作ってみた

foreach (var touch in Touch.activeTouches){
    switch (touch.phase){
        case TouchPhase.Began:
            touchPos = touch.screenPosition;
            break;
        case TouchPhase.Moved:
            Debug.Log( $"Touch: Id {touch.touchId} Position {touch.screenPosition} Phase {touch.phase}\n" );
            break;
        case TouchPhase.Ended:
            Vector2 shoot = (touch.screenPosition - touchPos);
            shoot.Normalize();
            Launch(shoot); // Launchは引数に発射方向を与えるように変更した
            break;
    }   
}

スライド方向に出るので、手裏剣の場合はこういう感じなのかな。
このままだとタッチするだけでも弾が出てしまうので、shootの長さが一定以上の場合みたいなのを入れないとダメっぽい。

Vector2 shoot = (touch.screenPosition - touchPos);
if( shoot.magnitude > (Screen.currentResolution.width/3) ){
    Debug.Log(shoot.magnitude + "/" + Screen.currentResolution.width/3);
    shoot.Normalize();
    Launch(shoot);
}

適当にスクリーンの1/3にしたら、なんとなく動いた。

今回は短いけど次は、ここ参考に指でなぞったところ(というか、始点と現在位置)に線を引きたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0