言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Transform.parent

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var parent: Transform;
public Transform parent;
public parent as Transform

Description

Transformの親

親を変更すると親からの相対的な位置、回転、スケールが変更されますが、ワールド空間としての位置、回転、スケールは維持されます。 See Also: ref::SetParent.

	// Makes the camera follow this object by
	// making it a child of this transform.

	// Get the transform of the camera
	var cameraTransform = Camera.main.transform; 	

	// make it a child of the current object
	cameraTransform.parent = transform; 

	// place it behind the current object
	cameraTransform.localPosition = -Vector3.forward * 5;
	
	// make it point towards the object
	cameraTransform.LookAt(transform);
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Transform cameraTransform = Camera.main.transform;
    void Example() {
        cameraTransform.parent = transform;
        cameraTransform.localPosition = -Vector3.forward * 5;
        cameraTransform.LookAt(transform);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public cameraTransform as Transform = Camera.main.transform

	def Example() as void:
		cameraTransform.parent = transform
		cameraTransform.localPosition = ((-Vector3.forward) * 5)
		cameraTransform.LookAt(transform)

他の例:

	// Detaches the transform from its parent.
	transform.parent = null;
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        transform.parent = null;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		transform.parent = null