Skip to content

Commit

Permalink
feat: screen shake on preparation room
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoneerC committed Sep 25, 2024
1 parent 614d956 commit a8f18ae
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
122 changes: 122 additions & 0 deletions Assets/Scenes/Preparation.unity
Original file line number Diff line number Diff line change
Expand Up @@ -5499,6 +5499,12 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 4459864850019384750, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
insertIndex: -1
addedObject: {fileID: 1248132680}
- targetCorrespondingSourceObject: {fileID: 4459864850019384750, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
insertIndex: -1
addedObject: {fileID: 1248132681}
- targetCorrespondingSourceObject: {fileID: 4459864850019384750, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
insertIndex: -1
addedObject: {fileID: 1248132689}
- targetCorrespondingSourceObject: {fileID: 4459864851310106424, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
insertIndex: -1
addedObject: {fileID: 848670200}
Expand Down Expand Up @@ -5552,6 +5558,11 @@ MonoBehaviour:
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
--- !u!20 &848670201 stripped
Camera:
m_CorrespondingSourceObject: {fileID: 4459864851310106426, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
m_PrefabInstance: {fileID: 848670198}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &862948266
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7042,6 +7053,117 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &1248132681
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1248132679}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b919c74d70599b94a9bc95b81da0ea38, type: 3}
m_Name:
m_EditorClassIdentifier:
mainCamera: {fileID: 848670201}
audioSource: {fileID: 1248132689}
explosionSound: {fileID: 8300000, guid: 792a87227660da44c950612c63d824a5, type: 3}
--- !u!82 &1248132689
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1248132679}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1001 &1259851975
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
55 changes: 55 additions & 0 deletions Assets/Scripts/CameraShake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using UnityEngine;

public class CameraShake : MonoBehaviour
{
public Camera mainCamera;
public AudioSource audioSource;
public AudioClip explosionSound;

private Transform _cameraTransform;
private Vector3 _originalPosition;

private void Awake()
{
if (mainCamera != null)
{
_cameraTransform = mainCamera.transform;
_originalPosition = _cameraTransform.localPosition;
StartDelayedShake(11f, 300f, 1f);
}
else
{
Debug.LogError("Main Camera is not assigned.");
}
}

private void StartDelayedShake(float delay, float duration, float magnitude)
{
StartCoroutine(DelayedShakeCoroutine(delay, duration, magnitude));
}

private IEnumerator DelayedShakeCoroutine(float delay, float duration, float magnitude)
{
yield return new WaitForSeconds(delay);

var elapsed = 0.0f;

audioSource.PlayOneShot(explosionSound);

while (elapsed < duration)
{
var x = Random.Range(-1f, 1f) * magnitude;
var y = Random.Range(-1f, 1f) * magnitude;

_cameraTransform.localPosition = new Vector3(x, y, _originalPosition.z);

elapsed += Time.deltaTime;

magnitude = Mathf.Lerp(magnitude, 0, elapsed / duration);
yield return null;
}

_cameraTransform.localPosition = _originalPosition;
}
}
Binary file added Assets/Sounds/Environment/distant-explosion.mp3
Binary file not shown.

0 comments on commit a8f18ae

Please sign in to comment.