Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이상현상 15 거미 사운드 continuous하게 3d 음향으로 변경 #180

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly15Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class Anomaly15Manager : MonoBehaviour

private void Start()
{
// Create and set up the interactive cube
// 상호작용할 수 있는 투명한 큐브
interactionCube = CreateInteractionCube();
StartCoroutine(SetTransparency(interactionCube));

// Start spawning spiders
// 거미 생성
StartCoroutine(SpawnSpiderRoutine());
}

Expand Down Expand Up @@ -100,22 +100,19 @@ private GameObject CreateInteractionCube()
return cube;
}

// Coroutine to set the transparency of the cube
// 투명하게 fadeout
private IEnumerator SetTransparency(GameObject cube)
{
yield return null; // Wait for one frame to ensure setup is complete

Renderer cubeRenderer = cube.GetComponent<Renderer>();

// Ensure it's using a unique material instance
cubeRenderer.material = new Material(Shader.Find("Standard"));

// Set the rendering mode to Transparent
cubeRenderer.material.SetFloat("_Mode", 3); // 3 = Transparent
cubeRenderer.material.color = new Color(0f, 0f, 0f, 0f); // Black albedo with 0 alpha
cubeRenderer.material.renderQueue = 3000; // Force render in transparent queue

// Additional settings to enforce transparency
cubeRenderer.material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
cubeRenderer.material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
cubeRenderer.material.SetInt("_ZWrite", 0);
Expand Down
38 changes: 8 additions & 30 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly15_spider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,29 @@ public class Anomaly15_spider : InteractableObject, IInteractable
[Header("Interaction Settings")]

private bool hasInteracted = false;
private Anomaly15Manager anomalyManager; // Reference to Anomaly15Manager
private Anomaly15Manager anomalyManager;
[Header("Audio Settings")]
public AudioClip spiderSoundClip;
private Transform cameraTransform; // Reference to the Main Camera's transform

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

private void Start()
{
// Find the Anomaly15Manager in the scene
anomalyManager = FindObjectOfType<Anomaly15Manager>();
if (anomalyManager == null)
{
Debug.LogError("Anomaly15Manager not found in the scene!");
}

GameObject mainCamera = GameObject.FindWithTag("MainCamera");
if (mainCamera != null)
{
cameraTransform = mainCamera.transform;
}

audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = spiderSoundClip;
audioSource.loop = true;
audioSource.spatialBlend = 2f; // 3D 음향으로 설정
audioSource.Play();
}

private void Update()
{
// Check the distance to the camera and play sound if within 5f
float distanceToCamera = Vector3.Distance(transform.position, cameraTransform.position);
Debug.Log(distanceToCamera);
if (distanceToCamera <= 10f && !hasInteracted)
{
if (!audioSource.isPlaying) // Start playing if not already playing
{
audioSource.Play();
}
}
else
if (hasInteracted && audioSource.isPlaying)
{
if (audioSource.isPlaying) // Stop playing if out of range
{
audioSource.Stop();
}
audioSource.Stop();
}
}

Expand All @@ -75,7 +54,6 @@ public void OnInteract()
if (anomalyManager != null)
{
anomalyManager.StopSpawning();
audioSource.Stop();
}

// Start coroutine to wait 2 seconds before destroying
Expand Down