【Tanks】ShellInstanceの親のGameObjectを取得するには? | Unity Forum | Tech Stadium Forum

【Tanks】ShellInstanc...
 
通知
すべてクリア

【Tanks】ShellInstanceの親のGameObjectを取得するには?  

  RSS

Student
(@student)
メンバー Moderator
結合: 5年前
投稿: 1522
21/07/2025 3:28 pm  

Rigidbody shellInstance =
            Instantiate(m_Shell, m_FireTransform.position, m_FireTransform.rotation) as Rigidbody;

上は、PrefabのShellのRigidbodyをInstantiateで取得するTankShooting.cs中の一文なのですが、
そのShellInstanceの親のGameObjectを取得するには、どうすればよいでしょうか?


引用
Teacher
(@admin)
メンバー Admin
結合: 5年前
投稿: 1447
21/07/2025 3:28 pm  

GetComponentInParentで取得できます。

逆に親から子要素を取得するにはGetComponentInChildrenを使用します。詳しい情報は以下のサイトを参考してください。
https://indie-game-creation-with-unity.hatenablog.com/entry/getcomponent-in-parent


返信引用
共有:
タイトルとURLをコピーしました