Skip to content

Commit

Permalink
Merge pull request #201 from 2024FALL-SWPP/ref/seozzi/Anomaly17
Browse files Browse the repository at this point in the history
이상현상 17 마이크 전선 스파크 refactoring
  • Loading branch information
seozzi authored Dec 14, 2024
2 parents 9b60302 + ba8f0fd commit ee1332c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 30 deletions.
25 changes: 22 additions & 3 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly17Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class Anomaly17Controller : AbstractAnomalyObject
{
public override string Name { get; } = "Anomaly17Controller";

public GameObject splitMicLinePrefab; // line_split prefab
public GameObject normalMicLinePrefab; // line_normal prefab
public GameObject splitMicLinePrefab;
public GameObject normalMicLinePrefab;
private GameObject currentMicLine; // line_split OR line_normal 중 현재 마이크 선 obejct
public AudioClip electricSparkSoundClip;

Expand All @@ -17,9 +17,28 @@ public class Anomaly17Controller : AbstractAnomalyObject
private Vector3 savedScale;
private Transform savedParent; // mic_line_normal

void Start()
public override bool StartAnomaly()
{
bool res = base.StartAnomaly();

ReplaceToSplitMic();

return res;
}

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

ReplaceToNormalMic();

return res;
}

private void Start()
{
StartAnomaly();
}

public void ReplaceToSplitMic()
Expand Down
69 changes: 42 additions & 27 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using UnityEngine;
using System.Collections;

public class Anomaly17_mic : InteractableObject, IInteractable
public class Anomaly17_mic : AbstractAnomalyInteractable
{
private bool hasInteracted = false;
public override string Name { get; } = "Anomaly17_mic";
private Anomaly17Controller anomalyManager;

// 스파크 세팅
Expand All @@ -24,7 +24,7 @@ public class Anomaly17_mic : InteractableObject, IInteractable
private float maxDistance = 15f;
private float minDistance = 2f;

private void Start()
public override bool StartAnomaly()
{
anomalyManager = FindObjectOfType<Anomaly17Controller>();
GameObject mainCamera = GameObject.FindWithTag("MainCamera");
Expand All @@ -38,6 +38,10 @@ private void Start()
audioSource.clip = electricSparkSoundClip;
audioSource.loop = true;
audioSource.playOnAwake = false;
audioSource.spatialBlend = 1f;
audioSource.minDistance = minDistance;
audioSource.maxDistance = maxDistance;
audioSource.rolloffMode = AudioRolloffMode.Linear;

// 라인 렌더러 설정
lineRenderer = gameObject.AddComponent<LineRenderer>();
Expand All @@ -56,14 +60,38 @@ private void Start()

// 전기 스파크 시작
StartElectricSpark();

return true;
}

private void Start()
{
StartAnomaly();
}

public override bool ResetAnomaly()
{
if (anomalyManager != null)
{
anomalyManager.ReplaceToNormalMic();

// 전기 스파크 효과 중지
StopAllCoroutines();
lineRenderer.enabled = false;

// 오디오 중지
audioSource.Stop();
}

return true;
}

private void Update()
{
// 카메라와의 거리 확인
float distanceToCamera = Vector3.Distance(transform.position, cameraTransform.position);

if (distanceToCamera <= maxDistance && !hasInteracted)
if (distanceToCamera <= maxDistance)
{
// 거리 기반 볼륨 조정
float volume = Mathf.InverseLerp(maxDistance, minDistance, distanceToCamera);
Expand Down Expand Up @@ -92,7 +120,7 @@ private void StartElectricSpark()

private IEnumerator ElectricSparkCoroutine()
{
while (!hasInteracted)
while (true)
{
lineRenderer.enabled = true;

Expand Down Expand Up @@ -134,31 +162,18 @@ public string GetInteractionPrompt()
return "Press Left Click to interact with the spark";
}

public bool CanInteract(float distance)
public override void OnInteract()
{
return !hasInteracted;
base.OnInteract();
GameManager.Instance.SetStageClear();

ResetAnomaly();
anomalyManager.ResetAnomaly();
}
// modified by 신채환
// CanInteract 메서드가 거리를 인자로 받도록 변경

public void OnInteract()
public override bool CanInteract(float distance)
{
if (hasInteracted) return;

hasInteracted = true;

if (anomalyManager != null)
{
anomalyManager.ReplaceToNormalMic();

// 전기 스파크 효과 중지
StopAllCoroutines();
lineRenderer.enabled = false;

// 오디오 중지
audioSource.Stop();
}

GameManager.Instance.SetStageClear(); // Clear the stage
if (distance < 5.0f) return true;
else return false;
}
}

0 comments on commit ee1332c

Please sign in to comment.