티스토리 뷰

<aside> ⚠️ 해당 프로젝트는 10일 안에 빠르게 끝낼 예정으로 기획했으므로 잘 짜여진 구조의 프로젝트가 아니며 검색을 통해 프로젝트를 진행하고 있다.

</aside>

2023년 3월 25일

public class Player : MonoBehaviour
{	
		[SerializeField]
    AudioClip stepSound;

    AudioSource audioSource;

		void Start()
    {
        audioSource = GetComponent<AudioSource>();
		}

		private void Move()
    {
				// 중략

        if (isMove)
        {
            if (!audioSource.isPlaying)
                audioSource.PlayOneShot(stepSound);

				// 중략

				}
		}
}

소리를 내는 오브젝트에 **AudioSource** 컴포넌트를 넣어줘야 한다. 안 그러면 정상 작동하지 않고 오류가 난다.

소리는 나지만 타이밍이 이상하다… 그래서 코드를 조금 손보았다.

public class Attackable : MonoBehaviour
{
    [SerializeField]
    GameObject keyboard;
    [SerializeField]
    TextMeshProUGUI[] score;
    [SerializeField]
    AudioClip attackSound;

    AudioSource audioSource;

    void Start()
    {
        audioSource = keyboard.transform.gameObject.GetComponent<AudioSource>();
        audioSource.clip = attackSound;
		}

		// 중략

		IEnumerator Attack()
    {
        //if (!audioSource.isPlaying)
          audioSource.Play();
            
          yield return new WaitForSeconds(attackTime);
          keyboardCollider.enabled = false;
          isDelay = false;
    }
}

공격하는 코루틴 사이에 넣어주었다. 사운드가 끝나는 부분에 여백 시간이 1초 안 되는데 살짝 거슬려서 **isPlaying** 을 조건문으로 걸지 않고 바로 **play** 시켰다. 한 번만 해주는 **playOneShot** 역시 사용하지 않았다. 게다가 오디오 소스는 게임오브젝트당 하나만 가능해서 발소리와 같이 나게 되는 조건이라면 둘 중 먼저 발동되는 소리만 나오기 때문에 키보드에 넣어주었다.

</aside>

2023년 3월 25일

public class Player : MonoBehaviour
{	
		[SerializeField]
    AudioClip stepSound;

    AudioSource audioSource;

		void Start()
    {
        audioSource = GetComponent<AudioSource>();
		}

		private void Move()
    {
				// 중략

        if (isMove)
        {
            if (!audioSource.isPlaying)
                audioSource.PlayOneShot(stepSound);

				// 중략

				}
		}
}

소리를 내는 오브젝트에 **AudioSource** 컴포넌트를 넣어줘야 한다. 안 그러면 정상 작동하지 않고 오류가 난다.

소리는 나지만 타이밍이 이상하다… 그래서 코드를 조금 손보았다.

public class Attackable : MonoBehaviour
{
    [SerializeField]
    GameObject keyboard;
    [SerializeField]
    TextMeshProUGUI[] score;
    [SerializeField]
    AudioClip attackSound;

    AudioSource audioSource;

    void Start()
    {
        audioSource = keyboard.transform.gameObject.GetComponent<AudioSource>();
        audioSource.clip = attackSound;
		}

		// 중략

		IEnumerator Attack()
    {
        //if (!audioSource.isPlaying)
          audioSource.Play();
            
          yield return new WaitForSeconds(attackTime);
          keyboardCollider.enabled = false;
          isDelay = false;
    }
}

공격하는 코루틴 사이에 넣어주었다. 사운드가 끝나는 부분에 여백 시간이 1초 안 되는데 살짝 거슬려서 **isPlaying** 을 조건문으로 걸지 않고 바로 **play** 시켰다. 한 번만 해주는 **playOneShot** 역시 사용하지 않았다. 게다가 오디오 소스는 게임오브젝트당 하나만 가능해서 발소리와 같이 나게 되는 조건이라면 둘 중 먼저 발동되는 소리만 나오기 때문에 키보드에 넣어주었다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
링크
Total
Today
Yesterday