コガネブログ

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

【Unity】Transform.SetParent の第2引数に渡す値によって何が変わるか

はじめに

m_sphere.SetParent( m_cube, true );

Transform.SetParent の第2引数には bool 値を渡すことができます
この bool 値に true、false を渡した時に何が変わるのか書き残しておきます

f:id:baba_s:20180314145305p:plain

f:id:baba_s:20180314145313p:plain

f:id:baba_s:20180314145319p:plain

このようにシーンに Cube と Sphere が存在する場合に
Cube を Sphere の親に設定してみます

true を渡す場合

m_sphere.SetParent( m_cube, true );

f:id:baba_s:20180314145305p:plain

f:id:baba_s:20180314145719p:plain

ワールド座標系における Sphere の位置や大きさが維持されます

false を渡す場合

m_sphere.SetParent( m_cube, false );

f:id:baba_s:20180314145917p:plain

f:id:baba_s:20180314145958p:plain

ローカル座標系における Sphere の位置や大きさが維持されます

参考ツイート