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

スクリプト言語

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

GameObject.Find

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

public static function Find(name: string): GameObject;
public static GameObject Find(string name);
public static def Find(name as string) as GameObject

Description

/name/ でゲームオブジェクトを検索し返します

/name/ のゲームオブジェクトが見つからない場合、nullを返します。 /name/ に '/' が含まれている場合は、それは階層のあるパス名のように判断されます。 この関数はアクティブのゲームオブジェクトのみ返します。 パフォーマンス上の理由から毎フレームでこの関数を使用せずに 代わりに、初回の結果をメンバー変数にキャッシュしたりGameObject.FindWithTagを使用することをお勧めします。

	var hand : GameObject;
	// This will return the game object named Hand in the scene.
	hand = GameObject.Find("Hand");

	// This will return the game object named Hand.
	// Hand must not have a parent in the hierarchy view!
	hand = GameObject.Find("/Hand");

	// This will return the game object named Hand,
	// which is a child of Arm -> Monster.
	// Monster must not have a parent in the hierarchy view!
	hand = GameObject.Find("/Monster/Arm/Hand");

	// This will return the game object named Hand,
	// which is a child of Arm -> Monster.
	// Monster may have a parent.
	hand = GameObject.Find("Monster/Arm/Hand");
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public GameObject hand;
    void Example() {
        hand = GameObject.Find("Hand");
        hand = GameObject.Find("/Hand");
        hand = GameObject.Find("/Monster/Arm/Hand");
        hand = GameObject.Find("Monster/Arm/Hand");
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public hand as GameObject

	def Example() as void:
		hand = GameObject.Find('Hand')
		hand = GameObject.Find('/Hand')
		hand = GameObject.Find('/Monster/Arm/Hand')
		hand = GameObject.Find('Monster/Arm/Hand')

この関数は、ロード時に他のオブジェクトの参照をもたせる時に非常に便利です。(例: MonoBehaviour.AwakeMonoBehaviour.Startの中で実行する) 毎フレームこの関数を呼び出すことは避けるようにしてください。例えばパフォーマンス上の理由でMonoBehaviour.Updateで使用することは避けてください。 一般的な使い方はMonoBehaviour.Start内でゲームオブジェクトの変数に割り当てることです。そうして、その変数をMonoBehaviour.Updateで使用します。

	// Find the hand inside Start and rotate it every frame
	private var hand : GameObject;
	function Start () {
		hand = GameObject.Find("/Monster/Arm/Hand");
	}
	
	function Update () {
		hand.transform.Rotate(0, 100 * Time.deltaTime, 0);
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    private GameObject hand;
    void Start() {
        hand = GameObject.Find("/Monster/Arm/Hand");
    }
    void Update() {
        hand.transform.Rotate(0, 100 * Time.deltaTime, 0);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private hand as GameObject

	def Start() as void:
		hand = GameObject.Find('/Monster/Arm/Hand')

	def Update() as void:
		hand.transform.Rotate(0, (100 * Time.deltaTime), 0)