I want to check objects in a List for their tags. And for each tag that matches “clean” an integer needs to be raised. Is this possible? If so, how can I accomplish this?
Thanks in advance!
P.S.: This is what I have now.
using UnityEngine;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class productManager : MonoBehaviour {
public string ownerName = "";
public List<Transform> ingredients = new List<Transform>();
//public int count = (from Object in List<Transform> ingredients where Object.Tags.Contains("clean") select Object).Count<Transform>();
void Start(){
ownerName = transform.name;
name = ownerName + "'s ingredients";
}
void Update(){
int count = (from Object in List<Transform> where Object.Tags.Contains("clean") select Object).Count<Transform>();
}
}
You can try with Linq:
int count = (from Object in List<T> where Object.Tags.Contains("clean") select Object).Count<T>()It returns to you the number of objects in that list that contains the tag “clean”.