コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Unity 2018.1.0b2 新機能「Vector2.Perpendicular」

はじめに

Unity 2018.1.0b2 の新機能の「Vector2.Perpendicular」を使用することで
指定された2Dベクトルに対して垂直な2Dベクトルを取得することができます

使用例

using UnityEngine;

public class Example : MonoBehaviour
{
    private void Awake()
    {
        print( Vector2.Perpendicular( new Vector2(  1,  0 ) ) ); // (  0,  1 )
        print( Vector2.Perpendicular( new Vector2(  0, -1 ) ) ); // (  1,  0 )
        print( Vector2.Perpendicular( new Vector2( -1,  0 ) ) ); // (  0, -1 )
        print( Vector2.Perpendicular( new Vector2(  0,  1 ) ) ); // ( -1,  0 )
    }
}

関連記事