현재 프로젝트에서 익숙한 방법으로 안내하겠습니다.
우선 코드에서 사용할 프리팹을 선언합니다.
public GameObject projectilePrefab;
C#
복사
사용할 프리팹을 연결해줍니다.
코드에서 필요한 곳에서 호출하여 사용합니다.
public IEnumerator Shot()
{
curMagazine--;
PlayClip(shot_AudioClip, shot_Volume);
playerCharacter_.playerUIEventInvoke();
// Use ObjectPool to Create projectile //
AmmoProjectile ammoProjectile = ObjectPoolManager.Instance.Pop(projectilePrefab).GetComponent<AmmoProjectile>();
ammoProjectile.transform.position = firePos.position;
ammoProjectile.transform.forward = playerCharacter_.FPCamera.transform.forward;
ammoProjectile.OnInit(stateMachine.Gun);
// -- //
// recoil
if (RecoilCoroutine != null) StopCoroutine(RecoilCoroutine);
RecoilCoroutine = OnRecoil();
StartCoroutine(RecoilCoroutine);
//Empty Check
if (isEmpty) stateMachine.ChangeState(stateMachine.EmptyState);
//shoot CoolTime
yield return YieldCacher.WaitForSeconds(curWeaponStat.fireDelay);
ShotCoroutine = null;
}
C#
복사
기본적으로
ObjectPoolManager.Instance.Pop(projectilePrefab)
과 같이 사용하며, 차후 Addressable이 적용된 이후에는
ObjectPoolManager.Instance.Pop(”BulletProjectile”) 과 같이 파일 명으로 호출 할 수 있습니다.