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 + "タグがついたオブジェクトはありません");
}
}
}