//Shake camera private IEnumerator Shake(CameraShakeType shakeType) { //Store original camera position Vector3 originalPosition = new Vector3(0, 0, 0); //Count elapsed time (in seconds) float ElapsedTime = 0.0f; //Repeat for total shake time if (SettingsController.Instance.isVibrate) { long pattern = (long) (300 * shakeTime * (int) shakeType); Vibration.Vibrate(pattern); } while (ElapsedTime < shakeTime * (int) shakeType) { //Pick random point on unit sphere Vector2 randomPoint2D = Random.insideUnitCircle * (int) shakeType; Vector3 randomPoint = originalPosition + new Vector3(randomPoint2D.x, randomPoint2D.y, 0); //Update Position cameraTransform.localPosition = Vector3.Lerp(cameraTransform.localPosition, randomPoint, Time.deltaTime * shakeSpeed * (int) shakeType); //Break for next frame yield return null; //Update time ElapsedTime += Time.deltaTime; } //Restore camera position cameraTransform.localPosition = originalPosition; }
public void Shake(CameraShakeType shakeType = CameraShakeType.DEFAULT, float duration = 0.3f) { this.shakeType = shakeType; this.duration = duration; hitDistance = duration / 2; hitCurrentDistance = 0; transform.localPosition = originalPos; transform.rotation = originalRotation; hitDirection = Random.insideUnitSphere; }
string TypeToAniName(CameraShakeType type) { if (type == CameraShakeType.Normal) { return "cameraShake"; } if (type == CameraShakeType.Small) { return "cameraShakeSmall"; } return "cameraShakeTiny"; }
public void GenerateImpulse(CameraShakeType type) { if (type == CameraShakeType.None) { return; } CameraShakeEntry entry = _cameraShakeEntries.Find(e => e.Type == type); if (entry != null) { //Debug.Log("CameraShakeType " + type.ToString()); entry.Source.GenerateImpulse(); return; } Debug.LogError("CameraShakeType " + type.ToString() + " doesn't exist in controller's entries! Check CameraShakeController object!"); }
public bool TakeDamage(Vector3 from, int damage) { if (!IsAlive()) { return(false); } if (_invincible) { Debug.Log("Entity is invincible!"); return(true); } bool itWasAlive = _currentDamage > 0; bool isDead = false; int calculatedDamage = CalculateDamage(damage); _currentDamage -= calculatedDamage; _lifeBarController.UpdateValue(_currentDamage, _data.MaxLife); CameraShakeType shakeType = _hurtCameraShakeType; CombatMessageType damageType = CombatMessageType.Normal; Vector3 damageForward = transform.position - from; if (itWasAlive) { isDead = _currentDamage <= 0; //TriggerEffect(damageForward.normalized, isDead, from); if (isDead) { _data.OnDeath?.Invoke(damageForward); damageType = CombatMessageType.Lethal; shakeType = _deathCameraShakeType; } else { _data.OnDamage?.Invoke(damageForward); } } SpawnCombatNumber(calculatedDamage.ToString(), damageType); _data.CameraShake.GenerateImpulse(shakeType); return(!isDead); }
public static void CameraShake(CameraShakeType type) { if (GameLogic.Release.Game.RoomState == RoomState.Runing) { switch (type) { case CameraShakeType.Crit: m_CameraAni.Play("CamShake_Crit"); break; case CameraShakeType.BridgeDown: m_CameraAni.Play("CamShake_BridgeDown"); break; case CameraShakeType.FirstDrop: m_CameraAni.Play("CamShake_FirstDrop"); break; case CameraShakeType.EquipDrop: m_CameraAni.Play("CamShake_EquipDrop"); break; } } }
public IEnumerator CameraShakeCo(CameraShakeType shakeType) { Anim.SetInteger("Shake", (int)shakeType); yield return(null); //Anim.SetInteger("Shake", 0); }
public void CameraShake(CameraShakeType shakeType) { StartCoroutine(CameraShakeCo(shakeType)); }
void Shake(CameraShakeType type) { camShakeAni.Stop(); camShakeAni.Play(TypeToAniName(type)); }
public void cameraShake(CameraShakeType shakeType) { StartCoroutine(Shake(shakeType)); }