void Update() { posAddShake = new Vector3(0, 3.8f, -2f); //Vector3.zero; rotAddShake = new Vector3(15.4f, 0, 0); // Vector3.zero; for (int i = 0; i < cameraShakeInstances.Count; i++) { if (i >= cameraShakeInstances.Count) { break; } CameraShakeInstance c = cameraShakeInstances[i]; if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive) { cameraShakeInstances.RemoveAt(i); i--; } else if (c.CurrentState != CameraShakeState.Inactive) { posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence); rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence); } } transform.localPosition = posAddShake; transform.localEulerAngles = rotAddShake; }
// Update is called once per frame void Update() { // Initialise the shake values posAddShake = Vector3.zero; rotAddShake = Vector3.zero; // Loop through shake instances for (int i = 0; i < cameraShakeInstances.Count; i++) { // Break from loop if exceeded instances count if (i >= cameraShakeInstances.Count) { break; } // Get the current camera shake instance CameraShakeInstance camShakeInstance = cameraShakeInstances[i]; // If the current instance is inactive if (camShakeInstance.CurrentState == CAMERA_SHAKE_STATE.INACTIVE && camShakeInstance.deleteOnInactive) { // Remove from list from the list cameraShakeInstances.RemoveAt(i); i--; } // Else if current camera shake instance is not inactive else if (camShakeInstance.CurrentState != CAMERA_SHAKE_STATE.INACTIVE) { // Update camera position and rotation posAddShake += CameraUtilities.MultiplyVectors(camShakeInstance.UpdateShake(), camShakeInstance.positionInfluence); rotAddShake += CameraUtilities.MultiplyVectors(camShakeInstance.UpdateShake(), camShakeInstance.rotationInfluence); } } // Set camera position and rotation transform.localPosition = posAddShake; transform.localEulerAngles = rotAddShake; }
void Update() { //if (Input.GetKeyDown(KeyCode.E)) //{ // Shake(CameraShakePresets.Bump); //} posAddShake = Vector3.zero; rotAddShake = Vector3.zero; for (int i = 0; i < cameraShakeInstances.Count; i++) { if (i >= cameraShakeInstances.Count) { break; } CameraShakeInstance c = cameraShakeInstances[i]; if (c.CurrentState == CameraShakeState.Inactive && c.DeleteOnInactive) { cameraShakeInstances.RemoveAt(i); i--; } else if (c.CurrentState != CameraShakeState.Inactive) { posAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.PositionInfluence); rotAddShake += CameraUtilities.MultiplyVectors(c.UpdateShake(), c.RotationInfluence); } } if (isUICamera) { posAddShake.z = UI_Z; } transform.localPosition = posAddShake; transform.localEulerAngles = rotAddShake; }