private void Awake() { if (m_TrailCount == 0) { TrailElement.ClearFreeElements(); Destroy(m_TrailElementPrefab); m_TrailElementPrefab = null; } m_TrailCount++; SetTrailParent(m_TrailParent); m_CurrentDisplacement = m_ZMoveMax; m_TrailElementPrefab = GameObject.Find("TrailElementReference"); if (m_TrailElementPrefab == null) { m_TrailElementPrefab = new GameObject(); m_TrailElementPrefab.AddComponent <SpriteRenderer>(); m_TrailElementPrefab.AddComponent <TrailElement>(); m_TrailElementPrefab.name = "TrailElementReference"; #if HIDE_TRAIL_IN_HIERRARCHY m_TrailElementPrefab.hideFlags = HideFlags.HideInHierarchy; #endif if (m_TrailParent == null) { m_TrailElementPrefab.transform.SetParent(m_GlobalTrailContainer, true); } else { m_TrailElementPrefab.transform.SetParent(m_LocalTrailContainer, true); } m_TrailElementPrefab.GetComponent <TrailElement>().Hide(false); } if (m_SpriteToDuplicate == null) { m_SpriteToDuplicate = GetComponent <SpriteRenderer>(); } if (m_SpriteToDuplicate == null) { Debug.LogError("You need a SpriteRenderer on the same GameObject as the SpriteTrail script. Else, you can set the SpriteToDuplicate variable from the inspector"); return; } m_PreviousPosSpawned = m_SpriteToDuplicate.transform.position; /*if (m_EnabledByDefault) * EnableTrailEffect();*/ }
void OnLevelWasLoaded() { TrailElement.ClearFreeElements(); Destroy(m_TrailElementPrefab); m_TrailElementPrefab = null; }