4
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity】タグが付いたオブジェクト数を数える

Last updated at Posted at 2016-07-31
TagScript.cs
using UnityEngine;
using System.Collections;

public class TagScript : MonoBehaviour {

	GameObject[] tagObjects;

	float timer = 0.0f;
	float interval = 2.0f;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		timer += Time.deltaTime;
		if(timer > interval){
			Check("HogeTag");
			timer = 0;
		}
	}

	//シーン上のBlockタグが付いたオブジェクトを数える
	void Check(string tagname){
		tagObjects = GameObject.FindGameObjectsWithTag(tagname);
		Debug.Log(tagObjects.Length); //tagObjects.Lengthはオブジェクトの数
		if(tagObjects.Length == 0){
			Debug.Log(tagname + "タグがついたオブジェクトはありません");
		}
	}
}

4
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?