- Home /
how to detect multiple target images using tag in unity?
how should I do if I want to scan multiple target images at once and display 1 output . the situation is I want to scan some foods in trolley which is in the trolley may have healthy and unhealthy foods. so I plan to classify them using tag. Then display only one output. for example if all the food in trolley is healthy will display healthy person but if there have one unhealthy food it will display sick people,
Answer by RamaKrishna39 · May 17 at 01:22 PM
public Image[] trolley;
int healthy=0;
int unhealthy = 0;
private void Start()
{
for(int i=0;i<trolley.Length;i++)
{
if(trolley[i].tag == "healthy") // can also use if(trolley[i].CompareTag("healthy"))
{
healthy += 1;
}
else if(trolley[i].tag == "unhealthy")
{
unhealthy += 1;
}
}
if(healthy == trolley.Length)
{
//Display Healthy Person
Debug.Log("Healthy");
}
else if(unhealthy>=1)
{
//Display sick Person
Debug.Log("Unhealthy");
}
}
hi, thank you for your response. I have try the solution you give but the output will always show unhealthy(sick person) even though I scan healthy food.
Hi, can you post what your food images are and their tags. I'm getting the output as sick person if there is atleast one image with tag as unhealthy food.
this is my tag for healthy food and unhealthy food. I notice my tag have wrong spell for unhealthy food. but I already change the tag name in the code according to my tag but still no working. my question is do target images can be recognise by using tag? because I have ask some people and they said target images cannot be accessed by tag . btw thank you so much in advance for your responding.