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

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GameObject.FindWithTag

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 FindWithTag(tag: string): GameObject;
public static GameObject FindWithTag(string tag);

Parameters

tag 検索するためのタグ

Description

/tag/でタグ付けされたアクティブなゲームオブジェクトを返します。もし見つからない場合は null を返します

この関数を使用する前にタグマネージャーでタグの設定を行う必要があります。タグが存在しない、または空文字や null を渡した場合は UnityException の例外が発生します。

var respawnPrefab : GameObject;
var respawn: GameObject;
    
// Instantiates respawnPrefab at the location 
// of the game object with tag "Respawn"
// This example assumes that a game object is tagged with "Respawn"
function Start()
{
    if (respawn==null)
        respawn = GameObject.FindWithTag ("Respawn");
    Instantiate (respawnPrefab, respawn.transform.position, respawn.transform.rotation);
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public GameObject respawnPrefab; public GameObject respawn; void Start() { if (respawn == null) respawn = GameObject.FindWithTag("Respawn"); Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation); } }