Skip to content

Commit

Permalink
이상현상 16 AbstractAnomalyInteractable 상속
Browse files Browse the repository at this point in the history
  • Loading branch information
seozzi committed Dec 14, 2024
1 parent d160c6f commit 4badf40
Showing 1 changed file with 24 additions and 44 deletions.
68 changes: 24 additions & 44 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly16_marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections;
using System.Collections.Generic;

public class Anomaly16_marker : InteractableObject, IInteractable
public class Anomaly16_marker : AbstractAnomalyInteractable
{
private bool hasInteracted = false;
private Anomaly16Manager anomalyManager; // Reference to Anomaly16Manager
public override string Name { get; } = "Anomaly16_marker";
private Anomaly16Controller anomalyManager;

private Transform cameraTransform;

Expand All @@ -28,7 +28,7 @@ public class Anomaly16_marker : InteractableObject, IInteractable
private const float endZ = -14.26f;
private bool isDrawing = false;

private void Start()
public override bool StartAnomaly()
{
// Set up the camera
GameObject mainCamera = GameObject.FindWithTag("MainCamera");
Expand All @@ -44,6 +44,11 @@ private void Start()
audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = markerSoundClip;
audioSource.loop = true;
audioSource.spatialBlend = 1f; // Enable 3D audio
audioSource.minDistance = 1f; // Start fading volume after 1 unit
audioSource.maxDistance = 15f; // Completely fade out at 15 units
audioSource.rolloffMode = AudioRolloffMode.Linear; // Smooth volume transitions


// Initialize LineRenderer for drawing
lineRenderer.positionCount = 1;
Expand All @@ -59,6 +64,21 @@ private void Start()
StartCoroutine(StartDrawingWithDelay());
}

public override bool ResetAnomaly()
{
if (anomalyManager != null)
{
anomalyManager.DestroyMarkerLineWithSound();
audioSource.Stop();
}
}

public override virtual OnInteract()
{
base.OnInteract();
GameManager.Instance.SetStageClear();
}

private IEnumerator StartDrawingWithDelay()
{
yield return new WaitForSeconds(3f); // Wait for 3 seconds
Expand All @@ -67,26 +87,12 @@ private IEnumerator StartDrawingWithDelay()

private void Update()
{
HandleAudioBasedOnDistance();
if (isDrawing)
{
DrawLineWithRandomness();
}
}

private void HandleAudioBasedOnDistance()
{
float distanceToCamera = Vector3.Distance(lastPosition, cameraTransform.position);
if (distanceToCamera <= 15f && !hasInteracted)
{
if (!audioSource.isPlaying) audioSource.Play();
}
else
{
if (audioSource.isPlaying) audioSource.Stop();
}
}

private void DrawLineWithRandomness()
{
if (lastPosition.z <= endZ)
Expand Down Expand Up @@ -177,30 +183,4 @@ private void UpdateMeshCollider()
meshCollider.sharedMesh = null;
meshCollider.sharedMesh = lineMesh;
}

public string GetInteractionPrompt()
{
return "Press Left Click to interact with the red line";
}

public bool CanInteract(float distance)
{
return !hasInteracted;
}
// modified by 신채환
// CanInteract 메서드가 거리를 인자로 받도록 변경

public void OnInteract()
{
if (hasInteracted) return;

hasInteracted = true;
if (anomalyManager != null)
{
anomalyManager.DestroyMarkerLineWithSound();
audioSource.Stop();
}
GameManager.Instance.SetStageClear(); // Mark the stage as clear

}
}

0 comments on commit 4badf40

Please sign in to comment.