Should I use async or a coroutine with this

So I have been working with coroutines for some time and have a code looking something like

IEnumerator startSpawning()
{
instantiate(circle, new Vector3(x,y,z), Quaternion.identity);
yield return new WaitForSeconds(.5f);
instantiate(circle, new Vector3(x,y,z), Quaternion.identity);
}

The problem conflicts with a part of my code that shrinks my torus (I call it a circle) over time. I want to be able to spawn multiple Torus’s during different times like .1 seconds apart but if I do that it stops shrinking the other one. How can I make sure the other one keeps on shrinking. This is what the code for the circle shrinking looks like.

void Update()
{
      if(circle.localscale.x != 0)
      {
      StartCoroutine("Shrink");
      isShrinking = true;
      }
      else
      {
      isShrinking = false;
      }
}
IEnumerator Shrink()
{
circle.localscale -= new Vector3(.01,.01,0);
yield return new WaitForSeconds(.5f) //Or some other value still working on it
}

That’s a rough estimate of the code (I’m at school right now). Should I start using async for this or should I keep using coroutines or should I start using something else. Thanks

Personally, I would use a tweening engine to shrink the circles. But that’s just me as it makes it super simple to handle stuff like this and there are several free tweening engines on the asset store. You just have to set a target scale and the time you want it to take to reach that scale.

Now, if you don’t want to use a tweening engine, it appears you are handling the shrinking and the spawning in the same script. Instead, break your shrinking logic off so each circle has a script on it that handles shrinking itself. If you need to, have your spawn script track the circles that you are spawning by adding them to a list when you instantiate it.

It’s just a matter of the logic of what is happening that is messing things up.

So you’re saying have two different scripts where one handles spawning and the other handles shrinking. If I were to do that wouldn’t I still run into the problem where one stops shrinking if I move onto instantiating the next object before the other one is done shrinking. Also this is for a rythm game. Not sure if that helps for answering anything.

No? Your shrinking script would be on the circle and would handle shrinking itself. While you can have the script as you have it, I would have it shrinking itself in a coroutine that has a loop with a yield inside to shrink.

So in this case, you start the coroutine when the circle prefab is instantiated (thus cloning the prefab). It targets itself and shrinks itself. No circle even knows any other circle exists.

Note, this would just be an idea.

void Start()
{
    StartCoroutine(ShrinkSelf());
}

IEnumerator ShrinkSelf()
{
    while(transform.localScale.x > 0)
    {
           //shrink code
           //yield code
    }

    //Add code here that does something to this object after shrinking is done if needed
}

I see now. Thank you so much