public void StartShake(float power, float duration) { mIsShaking = true; //The current shake mod being created. ShakeMod shakeMod = new ShakeMod(); shakeMod.mPower = power; shakeMod.mDuration = duration; mShakeModList.Add(shakeMod); }
private void ShakeAnimation() { //The power of the current shake mod. float power; //The duration of the current shake mod. float duration; //The total power being accumulated. float totalPower = 0.0f; for (int i = 0; i < mShakeModList.Count;) { ShakeMod curShakeMod = mShakeModList[i]; power = curShakeMod.mPower; duration = curShakeMod.mDuration; if (curShakeMod.mTimeElapsed < duration) { curShakeMod.mTimeElapsed += Time.deltaTime; totalPower += power; i++; } else { mShakeModList.RemoveAt(i); } } if (mShakeModList.Count == 0) { mIsShaking = false; } transform.position = new Vector3( transform.position.x + Random.Range(-totalPower, totalPower), transform.position.y + Random.Range(-totalPower, totalPower), transform.position.z + Random.Range(-totalPower, totalPower)); }