private void OnDestroy() { // if is quitting the application don't spawn object, // or else will cause memory leak! if (JCS_ApplicationManager.APP_QUITTING) { return; } // if switching the scene, don't spawn new gameObject. if (JCS_SceneManager.instance.IsSwitchingScene()) { return; } // trigger this effect? bool onTrigger = false; if (mActiveWhatever) { onTrigger = true; } // no need to check the rest. else { // if checking for hit list if (mActiveWithHitList) { if (mHitList.IsHit) { onTrigger = true; } } // if checking for destroy time. if (mActiveWithDestroyTime) { if (mDestroyObjectWithTime != null) { if (mDestroyObjectWithTime.TimesUp) { onTrigger = true; } } else { JCS_Debug.LogError( "You active the destroy time but without the JCS_DestroyObjectWithTime component..."); } } } // do not trigger this effect. if (!onTrigger) { return; } GameObject gm = new GameObject(); #if (UNITY_EDITOR) gm.name = "JCS_2DDestroyAnimEffect"; #endif SpriteRenderer sr = gm.AddComponent <SpriteRenderer>(); sr.sortingOrder = mOrderLayer; JCS_2DAnimation randAnim = m2DAnimPool.GetRandomAnim(); JCS_2DAnimation newAnim = gm.AddComponent <JCS_2DAnimation>(); newAnim.Active = randAnim.Active; newAnim.Loop = randAnim.Loop; newAnim.PlayOnAwake = randAnim.PlayOnAwake; newAnim.FramePerSec = randAnim.FramePerSec; // set the animation to just spawn animation. newAnim.SetAnimationFrame(randAnim.GetAnimationFrame()); newAnim.Play(); // add this event, so the when animation done play it will get destroy. JCS_2DDestroyAnimEndEvent das = gm.AddComponent <JCS_2DDestroyAnimEndEvent>(); das.LoopTimes = mLoopTimes; if (mSamePosition) { sr.transform.position = this.transform.position; } if (mSameRotation) { sr.transform.rotation = this.transform.rotation; } if (mSameScale) { sr.transform.localScale = this.transform.localScale; } // Random Effect if (mRandPos) { AddRandomPosition(sr); } if (mRandRot) { AddRandomRotation(sr); } if (mRandScale) { AddRandomScale(sr); } }
/* Functions */ private void Awake() { this.m2DAnimation = this.GetComponent <JCS_2DAnimation>(); }
/* Functions */ private void Awake() { // select first animation. mCurrentAnimation = mAnimations[mAnimCounter]; }