Skip to content

Commit

Permalink
이상현상 17 마이크 스파크: 소리 변경 및 스파크 시각적 효과 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
seozzi committed Nov 23, 2024
1 parent 85e3080 commit adb34b1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
splitMicLinePrefab: {fileID: 5539083566951112236, guid: e233a7c81a5e362428f5f5e41fa03f5d, type: 3}
normalMicLinePrefab: {fileID: 6415941471270356063, guid: 68994f463fb568649a46b36dca73c102, type: 3}
micBrokenSoundClip: {fileID: 8300000, guid: 0e5a81010ec724852bcb61aebbe2141c, type: 3}
electricSparkSoundClip: {fileID: 8300000, guid: 70add66df796c446386c8cac8012fe35, type: 3}
8 changes: 4 additions & 4 deletions 302/Assets/Scenes/DefaultGameScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -33966,8 +33966,8 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.03509348, y: 0.024665697, z: 0.12539476}
m_Center: {x: 0.001568737, y: 0.00081416254, z: 0}
m_Size: {x: 0.033585053, y: 0.024665697, z: 0.12539476}
m_Center: {x: 0.00081452366, y: 0.00081416254, z: 0}
--- !u!1001 &1561725255
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -35612,8 +35612,8 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.03635351, y: 0.028243784, z: 0.12539476}
m_Center: {x: 0.0021987641, y: 0.0014458442, z: 0}
m_Size: {x: 0.033529375, y: 0.028243784, z: 0.12539476}
m_Center: {x: 0.00078670616, y: 0.0014458442, z: 0}
--- !u!1 &1675446298
GameObject:
m_ObjectHideFlags: 0
Expand Down
4 changes: 2 additions & 2 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly17Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Anomaly17Manager : MonoBehaviour
public GameObject normalMicLinePrefab; // Reference to "line_normal" prefab from the project

private GameObject currentMicLine; // Stores the currently active mic line in the scene
public AudioClip micBrokenSoundClip; // To add to the Anomaly17_mic script
public AudioClip electricSparkSoundClip; // To add to the Anomaly17_mic script

private Vector3 savedPosition; // Saves the position of the original object
private Quaternion savedRotation; // Saves the rotation of the original object
Expand Down Expand Up @@ -54,7 +54,7 @@ public void ReplaceToSplitMic()
Anomaly17_mic micScript = newMicLine.AddComponent<Anomaly17_mic>();

// Set the necessary properties for the script
micScript.micBrokenSoundClip = micBrokenSoundClip; // Assign your desired AudioClip
micScript.electricSparkSoundClip = electricSparkSoundClip; // Assign your desired AudioClip
micScript.enabled = true; // Ensure the script is active

// Set the layer for interaction
Expand Down
116 changes: 99 additions & 17 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@ public class Anomaly17_mic : InteractableObject, IInteractable
private bool hasInteracted = false;
private Anomaly17Manager anomalyManager;

[Header("Electric Spark Settings")]
public int sparkSegments = 30; // 점 개수를 늘려 촘촘하게
public float sparkDuration = 0.1f; // 스파크 지속 시간을 짧게
public float sparkIntensity = 0.2f; // 랜덤성 강도 (작게 설정)
public float sparkInterval = 0.05f; // 스파크 사이의 간격을 짧게
public Color sparkColor = new Color(1f, 0.9f, 0.4f, 1f); // 연한 노란색 (R, G, B, A)

[Header("Spark Position")]
public Vector3 startPointOffset = new Vector3(0.9f, -1.8f, 0.7f); // Start 지점
public Vector3 endPointOffset = new Vector3(0.7f, -0.7f, 0.6f); // End 지점

private LineRenderer lineRenderer;

[Header("Audio Settings")]
public AudioClip micBrokenSoundClip;
private Transform cameraTransform; // Reference to the Main Camera's transform
public AudioClip electricSparkSoundClip;
private Transform cameraTransform;

private AudioSource audioSource; // Reference to the AudioSource component
private AudioSource audioSource;

[Header("Audio Range")]
public float maxDistance = 15f; // Max distance at which sound is heard
public float minDistance = 2f; // Distance where the sound is at full volume
public float maxDistance = 15f;
public float minDistance = 2f;

private void Start()
{
// Find the Anomaly17Manager in the scene
// Anomaly17Manager 찾기
anomalyManager = FindObjectOfType<Anomaly17Manager>();
if (anomalyManager == null)
{
Expand All @@ -32,34 +45,53 @@ private void Start()
cameraTransform = mainCamera.transform;
}

// 마이크 오디오 설정
audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = micBrokenSoundClip;
audioSource.clip = electricSparkSoundClip;
audioSource.loop = true;
audioSource.playOnAwake = false; // Ensure it doesn't play immediately
audioSource.spatialBlend = 0f; // Set to 0 for 2D sound (use 1 for 3D if needed)
audioSource.volume = 0f; // Start with zero volume
}
audioSource.playOnAwake = false;
audioSource.spatialBlend = 0f;
audioSource.volume = 0f;

// 라인 렌더러 설정
lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.positionCount = sparkSegments; // 점 개수
lineRenderer.startWidth = 0.05f; // 얇게
lineRenderer.endWidth = 0.05f;

// 발광하는 머티리얼 생성
Material sparkMaterial = new Material(Shader.Find("Unlit/Color"));
sparkMaterial.SetColor("_Color", sparkColor); // 색상 설정
sparkMaterial.EnableKeyword("_EMISSION"); // 발광 활성화
sparkMaterial.SetColor("_EmissionColor", sparkColor * 2f); // 발광 강도 조정

lineRenderer.material = sparkMaterial;

lineRenderer.enabled = false;

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

private void Update()
{
// Check the distance to the camera
// 카메라와의 거리 확인
float distanceToCamera = Vector3.Distance(transform.position, cameraTransform.position);
Debug.Log($"Distance to camera: {distanceToCamera}");

if (distanceToCamera <= maxDistance && !hasInteracted)
{
// Gradually adjust the volume based on the distance
// 거리 기반 볼륨 조정
float volume = Mathf.InverseLerp(maxDistance, minDistance, distanceToCamera);
audioSource.volume = volume;

if (!audioSource.isPlaying) // Start playing if not already playing
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
// Stop playing and ensure the volume is zero
// 소리 중지
if (audioSource.isPlaying)
{
audioSource.Stop();
Expand All @@ -68,6 +100,50 @@ private void Update()
}
}

private void StartElectricSpark()
{
StartCoroutine(ElectricSparkCoroutine());
}

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

// 스파크 생성
Vector3 startPoint = transform.position + startPointOffset; // Start 지점
Vector3 endPoint = transform.position + endPointOffset; // End 지점

GenerateSpark(startPoint, endPoint);

yield return new WaitForSeconds(sparkDuration);

lineRenderer.enabled = false;

yield return new WaitForSeconds(sparkInterval);
}
}

private void GenerateSpark(Vector3 startPoint, Vector3 endPoint)
{
// 라인 렌더러의 첫 번째와 마지막 점 설정
lineRenderer.SetPosition(0, startPoint);
lineRenderer.SetPosition(sparkSegments - 1, endPoint);

// 중간 점 생성
for (int i = 1; i < sparkSegments - 1; i++)
{
float t = (float)i / (sparkSegments - 1); // 0~1의 정규화된 값
Vector3 point = Vector3.Lerp(startPoint, endPoint, t);

// 불규칙하게 위치를 조정
point += Random.insideUnitSphere * sparkIntensity;

lineRenderer.SetPosition(i, point);
}
}

public string GetInteractionPrompt()
{
return "Press Left Click to interact with the mic";
Expand All @@ -87,9 +163,15 @@ public void OnInteract()
if (anomalyManager != null)
{
anomalyManager.ReplaceToNormalMic();

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

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

GameManager.Instance.SetStageClear(); // Mark the stage as clear
GameManager.Instance.SetStageClear(); // Clear the stage
}
}
Binary file added 302/Assets/Sounds/electric-sparks-6130.mp3
Binary file not shown.

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

Binary file not shown.

0 comments on commit adb34b1

Please sign in to comment.