前提
- unity 2017.4、2018.4
- staticクラス内で定義しない(拡張メソッドにしない)場合は、引数の
this
を取ってください。
できること
- オブジェクトがヒエラルキーで末弟かどうかを判定します。
コード
/// <summary>オブジェクトが最前かどうかを判定</summary>
public static bool IsLastSibling (this GameObject child) {
return (child.transform.GetSiblingIndex () == child.transform.parent.childCount - 1);
}
使い方
if (!this.IsLastSibling ()) return; // 自身が最前でなければ何もしない