Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/SoundBirdPuzzleSection/Sound Generator.cs
Damian e69542879b Redid the SoundBird Logic of flight
changed the flight of the bird to be able to have more control over the takeoff, loops and landing.
2025-09-24 17:24:51 +02:00

61 lines
1.9 KiB
C#

using Pixelplacement;
using UnityEngine;
public class SoundGenerator : MonoBehaviour
{
[SerializeField] private Sprite enterSprite;
[SerializeField] private Sprite exitSprite;
[SerializeField] private AudioClip enterSound;
[SerializeField] private AudioSource audioSource;
[SerializeField] private StateMachine soundBirdSMRef;
private bool playerInside = false;
private SpriteRenderer spriteRenderer;
void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer != null && exitSprite != null)
{
spriteRenderer.sprite = exitSprite; // Set to default on start
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!playerInside && other.CompareTag("Player"))
{
playerInside = true;
Debug.Log("Player entered SoundGenerator trigger!");
if (spriteRenderer != null && enterSprite != null)
{
spriteRenderer.sprite = enterSprite;
}
if (audioSource != null && enterSound != null)
{
audioSource.PlayOneShot(enterSound);
}
if (soundBirdSMRef != null && soundBirdSMRef.currentState.name == "SoundBird")
{
soundBirdSMRef.ChangeState("SoundBirdTakeoff"); // Replace with your actual method/state
}
// Play sound and change animation/state here if needed
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (playerInside && other.CompareTag("Player"))
{
playerInside = false;
Debug.Log("Player exited SoundGenerator trigger!");
if (spriteRenderer != null && exitSprite != null)
{
spriteRenderer.sprite = exitSprite;
}
// Reset animation/state here if needed
}
}
}