ゲームオブジェクト (GameObject)
Unity のシーンで用いられる全てのエンティティの基本クラス
参考:
UnityEngine.GameObject | Unity スクリプトリファレンス [公式]
コンポーネント (Component)
ゲームオブジェクトにアタッチされる全てのインスタンス実装の基本クラス
参考:
UnityEngine.Component | Unity スクリプトリファレンス [公式]
表示・非表示を切り替える
参考:
SetActive
参考:
SetActive を使ってゲームオブジェクトを表示・非表示にする方法 | FREE SWORDER
GameObject.SetActive | Unity Scripting API [Official]
How do I de/activate a gameobject of the hierarchy ingame? – Unity Forum
activeSelf / activeInHierarchy
activeSelf
:自身が有効かどうかを表すactiveInHierarchy
:自身と自身が属する上位のオブジェクト全てが有効な場合に有効となる
参考:
GameObject の active 状態を取得するときの注意点 | TECH Projin
ゲームオブジェクトを非アクティブにする | Unity マニュアル [公式]
GameObject.AddComponent
参考:
Unity でスクリプトからコンポーネントを取り付ける | かめくめ
Unity の AddComponent について調べてみた – Qiita
AddComponent に気をつけろ!| テラシュールブログ
GameObject.AddComponent | Unity スクリプトリファレンス [公式]
スクリプトでゲームオブジェクトを作成する
参考:
How do you create an empty gameobject in code and add it to the scene? – Unity Answers
スクリプトでオブジェクトの有効/無効を切り替える
参考:
Enable / Disable Gameobject on hierarchy when the scene start – Stack Overflow
Activating/Deactivating game objects in hierarchy based on their names – Stack Overflow
ヒエラルキーでオブジェクトの有効/無効を切り替える
参考:
nmxi/EDITOR_HierarchyTogles.cs – Hierarchy のオブジェクト名の左側にオブジェクトの有効化/無効化のボタンを表示 – GitHub Gist
スケーリング
参考:
Unity で Pivot を指定して同一スケーリングを行うスクリプト | e.blog
Strange behavior with non-uniform scaling and parenting | Unity Forum
Lossy Scaling implementation – Stack Overflow
Relative dimensions of gameobjects – Stack Overflow
Destroy / DestroyImmediate
参考:
Destroy() doesn’t create NullReferenceExeption? – Unity Forum
Object destruction and null links – Stack Overflow
null 合体演算子/null 条件演算子
Unity のゲームオブジェクトで使われる null
は C# のnull
ではないため、ゲームオブジェクトに対して null 合体演算子、及び null 条件演算子は使用できない。
null
であった場合に、C#の null
に変換するキャストを使用する。
public static T NullCast<T>(this T obj) where T : UnityEngine.Object => (obj != null) ? obj : (System.Object)null; GetComponent<Rigidbody>().NullCast()?.AddForce(force, mode);
参考:
Unity の GetCompornent() で Null 条件演算子が使えない – Qiita
null 合体演算子と null 条件演算子についてかるくまとめてみた | はなちるのマイノート
GameObject が削除されて null になったかどうかは null 合体演算子では確認できない | コガネブログ