Hello!
I have a random ghost generate when triggered, using Instantiate. They appear for a few seconds before destroying themselves. While they’re active, the player has to try and take a picture with as many of them on the screen at once as possible.
Everything in my code is working fine up until this point, and I’m just trying to figure out how to make a variable count the number of ghosts within the view of the camera. I looked at a few other similar questions, and a loop with “isVisible” counting the renderers is working, but the problem it counts each piece of the rendered items, which isn’t good for my ghosts which have multiple parts.
It also counts ALL renderers, not just those on the ghosts.
How would I count the number of ghosts (clones from Instantiate) that are on the screen?
Here’s my code for the counter:
if(Input.GetMouseButtonDown(2) && RaisedCamera == true){
Renderer[] renderers = (Renderer[])(FindObjectsOfType(typeof(Renderer)));
Count = 0;
foreach(Renderer i in renderers) {
if(i.isVisible) {
Count += 1F;
}
}