public bool CustomUpdate(float time) { for (int i = 0; i < trailerParts.Count; i++) { TrailerPart trailerPart = trailerParts[i]; trailerPart.spriteRenderer.transform.localScale -= Vector3.one * scaleDecreasePerSecond * time; if (trailerPart.CustomUpdate(time)) { trailerParts.Remove(trailerPart); Trailer.GiveTrailerPart(trailerPart); Debug.Log("Test"); } } if ((timeLastPart -= time) <= 0.0f) { TrailerPart trailerPart = Trailer.TakeTrailerPart(); trailerPart.Init(originalRenderer, lifeTime); trailerPart.transform.parent = transform; trailerParts.Add(trailerPart); timeLastPart = partDistance; } if ((duration -= time) <= 0.0f) { return(true); } return(false); }
private void Update() { SpriteRenderer[] allSpriteRenderer = new SpriteRenderer[trailerInformations.Keys.Count]; trailerInformations.Keys.CopyTo(allSpriteRenderer, 0); for (int i = 0; i < allSpriteRenderer.Length; i++) { SpriteRenderer spriteRenderer = allSpriteRenderer[i]; TrailerInformation trailerInformation; trailerInformations.TryGetValue(spriteRenderer, out trailerInformation); if (trailerInformation.CustomUpdate(Time.deltaTime)) { trailerInformations.Remove(trailerInformation.originalRenderer); for (int j = 0; j < trailerInformation.trailerParts.Count; j++) { TrailerPart trailerPart = trailerInformation.trailerParts[j]; GiveTrailerPart(trailerPart); } Destroy(trailerInformation.gameObject); } } }
public static void GiveTrailerPart(TrailerPart trailerPart) { trailerPartPool.Add(trailerPart); trailerPart.transform.parent = pool.transform; trailerPart.gameObject.SetActive(false); }