Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Transform.SetParent

マニュアルに切り替える
public void SetParent(Transform parent, bool worldPositionStays);

パラメーター

parent 設定する親
worldPositionStays true である場合、親との相対的な位置、角度、スケールは、設定される前のオブジェクトのワールド空間の位置、角度、スケールを維持して変更されます。

説明

Transform の親を設定します

このメソッドは worldPositionStays を false に設定することによりグローバル方向よりもローカル方向を保つ事が可能であるのを除くと parent プロパティーと同じです。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public GameObject player;

//Invoked when a button is clicked. public void Example(Transform newParent) { //Sets "newParent" as the new parent of the player GameObject. player.transform.SetParent(newParent);

//Same as above, except this makes the player keep its local orientation rather than its global orientation. player.transform.SetParent(newParent, false); } }