void Update() { if (Input.GetKeyDown(KeyCode.S)) { foreach (var shakeable in ManagerLocator.TryGetAll <IShakeable>()) { shakeable.Shake(intensity); } Invoke("MakePlayerDie", 0.1f); } }
public void ShakeIt(float shakeIntensity) { // Player is assumed to be at the origin var flatPosition = new Vector2(CachedTransform.position.x, CachedTransform.position.z); var distanceToPlayer = flatPosition.magnitude; var intensity = shakeIntensity * Mathf.Lerp(MAX_INTENSITY_FACTOR, MIN_INTENSITY_FACTOR, distanceToPlayer / MAX_DISTANCE); var shakeables = ManagerLocator.TryGetAll <IShakeable>(); if (shakeables != null && shakeables.Count > 0) { foreach (var shakeable in shakeables) { shakeable.Shake(intensity); } } }