2024-09-11 17:14:03 +09:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-09-12 13:29:32 +09:00
|
|
|
[RequireComponent(typeof(AudioSource))]
|
2024-09-11 17:14:03 +09:00
|
|
|
public class WeaponController : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private GameObject bulletPrefab;
|
|
|
|
[SerializeField] private Transform firePos;
|
2024-09-12 13:27:09 +09:00
|
|
|
[SerializeField] private AudioClip fireSfx;
|
|
|
|
|
|
|
|
private new AudioSource audio;
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
audio = GetComponent<AudioSource>();
|
|
|
|
}
|
2024-09-11 17:14:03 +09:00
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
2024-09-11 17:19:07 +09:00
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
|
|
{
|
|
|
|
// 총알 생성 : bulletPrefab을 왼쪽 마우스 버튼 클릭할 때 마다 생성
|
|
|
|
// Instantiate(생성할프리팹, 위치, 각도)
|
|
|
|
Instantiate(bulletPrefab, firePos.position, firePos.rotation);
|
2024-09-12 13:27:09 +09:00
|
|
|
|
|
|
|
// 총소리 사운드 재생
|
|
|
|
audio.PlayOneShot(fireSfx, 0.8f);
|
2024-09-11 17:19:07 +09:00
|
|
|
}
|
2024-09-11 17:14:03 +09:00
|
|
|
}
|
|
|
|
}
|