반응형
- 코드 작성
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public AudioClip walkingSound;
private AudioSource audioSource;
private bool isWalking;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
if (isWalking)
{
if (!audioSource.isPlaying)
{
audioSource.PlayOneShot(walkingSound);
}
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("바닥"))
{
isWalking = true;
}
}
void OnCollisionExit(Collision collision)
{
if (collision.gameObject.CompareTag("바닥"))
{
isWalking = false;
}
}
}
반응형