Skip to content

Commit

Permalink
Merge pull request #159 from 2024FALL-SWPP/chaehwan/anomaly23
Browse files Browse the repository at this point in the history
Add sound & bug fix
  • Loading branch information
Prown0 authored Nov 27, 2024
2 parents d47eadd + 30061f6 commit 4fc9934
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 6 deletions.
101 changes: 100 additions & 1 deletion 302/Assets/Prefabs/Anomaly23/ghost.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ GameObject:
- component: {fileID: 6077576747107725253}
- component: {fileID: 5615054433689430107}
- component: {fileID: 6691339936817308490}
- component: {fileID: 3035267094544484457}
m_Layer: 0
m_Name: ghost
m_TagString: Untagged
Expand Down Expand Up @@ -776,7 +777,105 @@ MonoBehaviour:
speedInit: 1
speedDelta: 5
durationChase: 25
durationFade: 5
durationBlow: 5
timeAudioStart: 3
durationFade: 3
--- !u!82 &3035267094544484457
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6383441288876432308}
m_Enabled: 0
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: c52ad1d603f6a794aad196f6376d508d, type: 3}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 1
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!1 &6612614341887459618
GameObject:
m_ObjectHideFlags: 0
Expand Down
73 changes: 68 additions & 5 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly23_Ghost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine;

[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(AudioSource))]
public class Anomaly23_Ghost : SCH_AnomalyObject
{
/**********
Expand All @@ -17,18 +18,24 @@ public class Anomaly23_Ghost : SCH_AnomalyObject
public float speedInit;
public float speedDelta;
public float durationChase;
public float durationBlow;
public float timeAudioStart;
public float durationFade;

// 애니메이터
private Animator _animator;

// 오디오 소스
private AudioSource _audioSource;

// 오브젝트
private GameObject _objectPlayer;
private GameObject _objectCamera;

// 내부 수치
private float _timeStart;
private bool _isChasing;
private bool _isCatched;

/**************
* properties *
Expand All @@ -47,10 +54,14 @@ void OnCollisionEnter(Collision other)
if (other.collider.CompareTag("Player") && _isChasing) {
PlayerController script = _objectPlayer.GetComponent<PlayerController>();

_isCatched = true;
if (script != null) {
Log("Call `script.GameOver` begin");
script.GameOver();
Log("Call `script.GameOver` end");

Log("Call `FadeAudioAsync` asynchronously");
StartCoroutine(FadeAudioAsync());
} else {
Log("Call `script.GameOver`: failed", mode: 1);
}
Expand All @@ -72,15 +83,12 @@ void Update()
transform.LookAt(positionTarget);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
_animator.SetFloat("Speed", speed);
} else {
} else if (!_isCatched) {
_isChasing = false;

Log("Call `Manager.InteractionSuccess` begin");
Manager.InteractionSuccess();
Log("Call `Manager.InteractionSuccess` end");

Log("Call `BlowAsync` asynchronously");
StartCoroutine(BlowAsync());
}
}
}
Expand All @@ -103,6 +111,15 @@ protected override bool InitFields()
res = false;
}

// _audioSource
_audioSource = GetComponent<AudioSource>();
if (_audioSource != null) {
Log("Initialize `_audioSource`: success");
} else {
Log("Initialize `_audioSource`: failed", mode: 1);
res = false;
}

// _objectPlayer
_objectPlayer = GameObject.Find(namePlayer);
if (_objectPlayer != null) {
Expand All @@ -129,6 +146,10 @@ protected override bool InitFields()
_isChasing = true;
Log("Initialize `_isChasing`: success");

// _isCatched
_isCatched = false;
Log("Initialize `_isChasing`: success");

return res;
}

Expand All @@ -144,13 +165,55 @@ protected override bool SetAnomaly()
transform.position = position;
Log("Set position: success");

Log("Call `StartAudioAsync` asynchronously");
StartCoroutine(StartAudioAsync());

return res;
}

// 이상현상을 초기화하는 메서드
public override bool ResetAnomaly()
{
bool res = base.ResetAnomaly();

_audioSource.enabled = false;
Log("Reset audio source: success");

Log("Call `BlowAsync` asynchronously");
StartCoroutine(BlowAsync());

return res;
}

/***********
* methods *
***********/

// 시작하고 일정 시간 후 오디오 소스를 시작하는 메서드
private IEnumerator StartAudioAsync()
{
yield return new WaitForSeconds(timeAudioStart);

_audioSource.enabled = true;
}

// 오디오 소스 볼륨을 서서히 줄이는 메서드
private IEnumerator FadeAudioAsync()
{
float timeStart = Time.time;
float time;

yield return null;

while ((time = Time.time - timeStart) < durationFade) {
_audioSource.volume = 1.0f - time / durationFade;

yield return null;
}

_audioSource.enabled = false;
}

// 지속시간 동안 바람빠지다가 사라지는 메서드
private IEnumerator BlowAsync()
{
Expand All @@ -160,7 +223,7 @@ private IEnumerator BlowAsync()

yield return new WaitForSeconds(0.1f);

while ((time = Time.time - timeStart) < durationFade) {
while ((time = Time.time - timeStart) < durationBlow) {
float scale = (float)(random.LogNormalDist(0.0, 1.0) * 1.5);

transform.rotation = Random.rotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Anomaly23_Laptop : SCH_AnomalyObject
void Update()
{
if (_script != null && _script.Index != anomalyScreenIndex) {
_index = _script.Index;
_script.ChangeScreen(anomalyScreenIndex);
}
}
Expand Down
8 changes: 8 additions & 0 deletions 302/Assets/Sounds/Anomaly23.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
22 changes: 22 additions & 0 deletions 302/Assets/Sounds/Anomaly23/bright-violin-hit_E_major.wav.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fc9934

Please sign in to comment.