I’ve written a corountine to use a sprite mask to show nearby sprites and so far, that works flawlessly. However, when it comes to changing the opacity of every gameobject in the scene, I’m starting to find troubles. There isn’t very many gameobjects in the current scene so I’m not too worried about the optimization. I created an array to store all the gameobjects here:
public GameObject[] objects;
and then I try to grab all the objects in the scene with this:
// Start is called before the first frame update
void Start()
{
playerTransform = transform;
objects = GameObject.FindGameObjectsWithTag("Untagged");
}
and this is the method I’m using:
IEnumerator sonar()
{
sonarMask.transform.DOScale(new Vector3(20f, 20f, 0f), 0.7f);
yield return new WaitForSeconds(1f);
Debug.Log("Started loop");
foreach (var obj in objects)
{
Debug.Log("Found obj");
SpriteRenderer spriteRenderer = obj.GetComponent<SpriteRenderer>();
if (spriteRenderer != null)
{
Debug.Log("started fade");
spriteRenderer.DOFade(0f, 5f);
}
}
yield return null;
}
The script never displays “Found obj” or “started fade” leading me to believe that there are no gameobjects in the array. Can I get some help?