IEnumerator StartSpawn()
{
if(coroutineEnabled){
index = Random.Range(0, articals.Count);
GameObject _temp = Instantiate(articals[index],gameObject.transform.position, Quaternion.identity) as GameObject;
_temp.transform.SetParent(transform,true);
_temp.transform.localScale = Vector2.one;
_temp.transform.localPosition = new Vector2(Screen.width,transform.localPosition.y);
_temp.LeanMoveLocalX(-Screen.width, 15f).setOnComplete(DestroyGameObject);
yield return new WaitForSeconds(waitTime);
StartCoroutine(StartSpawn());
}
}
I have a coroutine that spawn a gameObject and moves it across the screen with LeanTween. but at an event i want to stop all the gameObjects at their positions.
Google tells me there’s a cancel
and a reset
, plus you likely can just Destroy() the tween, leaving the object alone.
1 Like
Take a look at the documentation under .cancel LeanTween - LeanTween