-
๋ณธ ํ๋ก์ ํธ๋ ๋ฉํฐํ๋ ์ด ๊ฒ์์ด๋ฏ๋ก, ๋ ๋ช ์ด์์ ํ๋ ์ด์ด๊ฐ ๋์์ ์ ์ํด์ผ ๊ธฐ๋ฅ์ ํ ์คํธํ ์ ์์ต๋๋ค.
-
๊ฐ์ฅ ๊ฐํธํ ํ ์คํธ ๋ฐฉ๋ฒ:
- ํ๋๋ Build(Build Settings โ Build) ํ์ฌ ์คํ (.exe ๋๋ Android APK ๋ฑ)
- ๋ค๋ฅธ ํ๋๋ ์๋ํฐ(Play ๋ชจ๋) ์์ ์คํ
-
๊ฒ์ ์์ ์ ๋ฐ๋์ LobbyScene๋ถํฐ ์คํํด์ผ Photon ์๋ฒ์ ์ ์์ ์ผ๋ก ์ฐ๊ฒฐ๋ฉ๋๋ค.
GameManager๋ ํ๋ก์ ํธ ๋ด ๋ชจ๋ ๋งค๋์ ๋ค์ ์ค์ ์ด๊ธฐํ ๋ฐ ๋ฆด๋ฆฌ์ฆ, ์ฑ๊ธํค ์ ๊ทผ ๋ฐฉ์์ ์ ๊ณตํฉ๋๋ค.
public static DataManager Data { get; } = new DataManager();
var managers = new List<IManager>
{
UI,
Scene,
Resource,
Photon,
Data,
};
private static void Relese()
{
Scene?.Release();
UI?.Release();
Resource?.Release();
Photon?.Release();
Data?.Release();
}- ๊ฐ ๋งค๋์ ๋
static์ผ๋ก ์ ์ธ๋๋ฏ๋กGameManager.Data.๊ธฐ๋ฅ()์ฒ๋ผ ์ ๊ทผํฉ๋๋ค. - ์ฌ ์ ํ ์์๋ ์ ์ง๋๋ฉฐ ์ ์ญ์์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
UIManager๋ ํ์ UI์ ์์ฑ, ํ์, ์จ๊น, ์คํ ๊ด๋ฆฌ๋ฅผ ๋ด๋นํฉ๋๋ค.
| ๋ฉ์๋ | ์ค๋ช |
|---|---|
| ShowPopup(string popupName) | ๋น๋๊ธฐ๋ก ํ์ ์์ฑ ๋ฐ ํ์ (์ฌ์ฌ์ฉ ๊ฐ๋ฅ) |
| HidePopup(IPopupPresenter popup) | ํ์ ์คํ์์ ์ ๊ฑฐ ๋ฐ ์จ๊น |
| IsPopupStack(string popupName) | ํ์ ์คํ์ ํด๋น ์ด๋ฆ ์กด์ฌ ์ฌ๋ถ ํ์ธ |
| CreatePopup(string popupName) | ์ฃผ์ ๊ธฐ๋ฐ์ผ๋ก ํ์ ์ค๋ธ์ ํธ ์์ฑ |
void GetPlayerInput()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
var popup = GameManager.UI.IsPopupStack(matchPopupName);
if (popup != null)
GameManager.UI.HidePopup(popup);
else
GameManager.UI.ShowPopup(matchPopupName).Forget();
}
}- ํ์ ํ๋ฆฌํน์ ResourceManager๋ฅผ ํตํด ๋ก๋ ๊ฐ๋ฅํด์ผ ํจ
IPopupPresenter๋ฅผ ๊ตฌํํ MonoBehaviour ์ปดํฌ๋ํธ๋ฅผ ํฌํจํด์ผ ํจ- ์ต์ํ
ShowView(),HideView()๋ฉ์๋๋ฅผ ๊ตฌํํด์ผ ํจ
- PopupType ๊ธฐ๋ฐ ๋ถ๊ธฐ ํ์ฅ
- MVP ๊ตฌ์กฐ ์ ์ฉ ์
IPresenter๋ก ์ผ๋ฐํ ๊ฐ๋ฅ - PresenterBase.cs ๋ฑ์ ์ด์ฉํ ์ด๋ฒคํธ ์ฐ๋ ๊ตฌ์กฐ ๊ฐ๋ฅ
Unity Addressables ๊ธฐ๋ฐ์ผ๋ก ๋น๋๊ธฐ ๋ฐฉ์ ๋ฆฌ์์ค ๋ก๋ฉ/์บ์ฑ์ ์ง์ํฉ๋๋ค.
- ์ฃผ์ ๊ธฐ๋ฐ GameObject ๋น๋๊ธฐ ๋ก๋ฉ
- ์ด๋ฆ ์ ๋ฆฌํ์ฌ ์บ์ ํค ์ผ๊ด์ฑ ์ ์ง
- ํน์ ์ปดํฌ๋ํธ ๋จ์ ๋ก๋ฉ ์ง์
- ๋ด๋ถ ํธ๋ค ์บ์ฑ
private readonly Dictionary<string, AsyncOperationHandle<GameObject>> _instantiateResource;
async UniTask<GameObject> Instantiate(string address, Transform parent = null);
async UniTask<T> Instantiate<T>(string address, Transform parent = null) where T : class;์์:
GameObject avatar = await GameManager.Resource.Instantiate("PlayerInfo", parent);
return await GameManager.Resource.Instantiate<IPopupPresenter>(popupName, container);PhotonManager๋ ์๋ฒ ์ฐ๊ฒฐ, ๋งค์นญ, ๋ฃธ ์์ฑ, ์ฌ ์ ํ ๋ฑ์ ์์ ๋คํธ์ํฌ ๋ก์ง์ ๊ด๋ฆฌํฉ๋๋ค.
-
์์ ๋งค๋์ :
PhotonManager- ์๋ฒ ์ฐ๊ฒฐ, ๋งค์นญ, GamePhase์ ๋ฐ๋ผ ์ฌ ์ ํ
- ๊ฐ ์ฌ๋ณ
IScenePhotonManager์ด๊ธฐํ
-
ํ์ ๋งค๋์ :
WaitingRoomPhotonManager: ๋๊ธฐ๋ฐฉ ์ ์ฅ/์ค๋น ์ํ ์ฒ๋ฆฌInGamePhotonManager: ์ธ๊ฒ์ ์กฐ์, ์นํจ, ์บ๋ฆญํฐ ๋๊ธฐํ ๋ฑ ์ฒ๋ฆฌ
ConnectToPhoton()
โ OnConnectedToMaster() โ JoinLobby()
โ OnJoinedLobby() โ StartRandomMatch()
โ JoinRandomRoom() โ OnJoinRandomFailed() โ CreateRoom()
โ OnJoinedRoom() โ ์ฌ ์ ํ
- ๋๊ธฐํ ๋์ ์ค๋ธ์ ํธ์๋ ๋ฐ๋์ PhotonView ์ปดํฌ๋ํธ๊ฐ ์์ด์ผ ํจ
photonView.IsMine์ฒดํฌ๋ฅผ ํตํด ๋ก์ปฌ ํ๋ ์ด์ด๋ง ์กฐ์ ๊ฐ๋ฅํ๋๋ก ์ฒ๋ฆฌ
void Update()
{
if (!photonView.IsMine) return; // ๋ด ์บ๋ฆญํฐ๋ง ์กฐ์
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.Translate(new Vector3(h, 0, v));
}GameObject bullet = PhotonNetwork.Instantiate("Projectiles/Bullet", spawnPos, rotation);
bullet.GetComponent<Projectile>().isRPCFire = true;- ๋ก์ปฌ์์๋ง Instantiate ๊ฐ๋ฅํ๋๋ก ๋ถ๊ธฐ ์ฒ๋ฆฌ
- ํํ์ด ์ด๋ ์ค์ผ ๋, ์์น๋
photonView.IsMine์ธ ๊ฒฝ์ฐ๋ง ์ด๋์ํค๊ณ ๊ทธ ์ธ์๋ ๋๊ธฐํ ๋๊ธฐ
[PunRPC]
void RPC_Fire(float angle, bool isRight)
{
SetActive(true);
hasLaunched = true;
transform.rotation = Quaternion.Euler(0, 0, angle);
// ๊ธฐํ ์ดํํธ ์คํ
}- RPC๋
photonView.RPC("RPC_Fire", RpcTarget.All, angle, isRight);ํ์์ผ๋ก ํธ์ถ
- ์์ง์ ๋ฐ ์ ๋๋ฉ์ด์
๋๊ธฐํ๋ฅผ ์ํด PhotonView์
Observed Components์Transform,Animator๋ฅผ ํฌํจ์์ผ์ผ ํจ Animator๊ฐ ์์ผ๋ฉด Mecanim ๊ธฐ๋ฐ ๋๊ธฐํ๊ฐ ๋ถ๊ฐ๋ฅํ๋ฏ๋ก, ์ ๋๋ฉ์ด์ ์์คํ ์ ๋ฐ๋์ Mecanim(Animator Controller) ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํํด์ผ ํจ
- PhotonStream์ ์ด์ฉํด ์ข์ฐ ๋ฐฉํฅ, ๊ฐ๋ ๋ฑ ๊ฐ๋ณ ๋ฐ์ดํฐ๋ฅผ ์ง์ ๋ณด๋ด๋ ๋ฐฉ์์ผ๋ก ๋๊ธฐํํ ์ ์์ต๋๋ค.
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
bool isLeftDirection = crosshairMouse.AimDirection.x < 0.1f;
stream.SendNext(isLeftDirection);
}
else
{
bool isLeftDirection = (bool)stream.ReceiveNext();
Debug.Log("isLeftDirection: " + isLeftDirection);
isRightDirection = isLeftDirection;
SetBodyPartsDirection(isLeftDirection ? Direction.Left : Direction.Right);
}
}- ์ฃผ๋ก ์บ๋ฆญํฐ์ ํ์ ๋ฐฉํฅ, ๋ถ์ ์ํ, ์์ ๋ฐฉํฅ ๋ฑ์ ์ค์๊ฐ์ผ๋ก ๋ค๋ฅธ ํ๋ ์ด์ด์๊ฒ ์ ๋ฌํ ๋ ์ฌ์ฉ๋ฉ๋๋ค.
๊ธฐ์กด ์คํ์์ค๋ Animation Clip๋ง ์ฌ์ฉํ๋ ๋ฐฉ์์ด์์ผ๋, ๋ณธ ํ๋ก์ ํธ์์๋ Photon๊ณผ์ ํธํ์ ์ํด Animator Controller ๊ธฐ๋ฐ์ Mecanim ๊ตฌ์กฐ๋ก ๋ณ๊ฒฝํ์์ต๋๋ค.
- ๊ฐ ๋ฌด๊ธฐ๋ง๋ค ์ ์ฉ Animator Controller ์์ฑ (
Idle,BasicShot,StrongShot๋ฑ ์ํ ์ ์) animator.SetInteger("WeaponAction", ...)๋ฐฉ์์ผ๋ก ์ํ ์ ์ด ๊ตฌํAnimator์ปดํฌ๋ํธ๋ PhotonView์ Observed Components์ ํฌํจํ์ฌ ๋คํธ์ํฌ ์ ๋๋ฉ์ด์ ๋๊ธฐํ ๊ฐ๋ฅ
์ด๋ฅผ ํตํด ๋ฉํฐํ๋ ์ด ํ๊ฒฝ์์๋ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ผ๊ด๋ ์ ๋๋ฉ์ด์ ์ฌ์์ด ๊ฐ๋ฅํด์ก์ผ๋ฉฐ, ์ปค์คํ ๋ฌด๊ธฐ ๋์ ๋ฐ ํผ๊ฒฉ/๋ฐ์ฌ ์ดํํธ๋ ์ ํํ ๋๊ธฐํ๋ฉ๋๋ค.
๋ณธ ๊ฐ์ด๋๋ ๋ฉํฐํ๋ ์ด ๊ธฐ๋ฐ์ ์ํ ๊ฒ์์์ ๋ฐ์ํ๋ ์ ๋ฐ์ ์ธ ์์คํ ๊ตฌ์ฑ๊ณผ Photon ํ๊ฒฝ์์์ ๋๊ธฐํ, ์ ๋ ฅ ๋ถ๊ธฐ, ์ ๋๋ฉ์ด์ ์ฒ๋ฆฌ ๋ฑ์ ์ค์ฌ์ผ๋ก ์์ฑ๋์์ผ๋ฉฐ, ์ถํ ํ ํ๋ก์ ํธ๋ ์์ฉ ๊ฐ๋ฐ ํ๊ฒฝ์์๋ ํ์ฅ ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ก ๊ตฌ์ฑ๋์ด ์์ต๋๋ค.
Weapon.cs๋ ๊ฐ ๋ฌด๊ธฐ๋ณ๋ก ํ์ํ ์คํ๋ผ์ดํธ, ํ๋ฆฌํน, ์ค๋์ค ํด๋ฆฝ ๋ฑ์ ๋น ๋ฅด๊ฒ ๋ก๋ํ๊ธฐ ์ํด ์์ฒด์ ์ธ ๋ฆฌ์์ค ๋ก๋ฉ ํจ์๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ์ด ๋ฐฉ์์ ๋ฒ์ฉ ๋ฆฌ์์ค ๋งค๋์ ๋ฅผ ์ฌ์ฉํ์ง ์๊ณ , ๋ฌด๊ธฐ ์์คํ
์ฒ๋ผ ์ ํ๋ ๋ฒ์์ ํด๋์ค์์๋ง ์ฌ์ฉํ๋ ๋ฆฌ์์ค๋ฅผ ๊ฐ๋จํ ๋ก๋ํ ์ ์๋๋ก ์ค๊ณ๋์์ต๋๋ค.
โป ๋ฒ์ฉ ๋ฆฌ์์ค ๋ก๋ฉ์ด ํ์ํ ๊ฒฝ์ฐ์๋
ResourceManager+AddressableAssets๊ตฌ์กฐ ์ฌ์ฉ์ ๊ถ์ฅํฉ๋๋ค. ๋จ, ๋ฌด๊ธฐ ์์คํ ์ฒ๋ผ ํ ํด๋์ค์ ํ์ ๋ ๋ฆฌ์์ค๋ง ํ์ํ ๊ฒฝ์ฐ, ํ์ฌ ๊ตฌ์กฐ์ฒ๋ผResources.Load()๊ธฐ๋ฐ์ ์ง์ ๋ก๋ฉ ๋ฐฉ์์ด ์ ๋ฆฌํ ์ ์์ต๋๋ค.
| ๋ฉ์๋๋ช | ์ค๋ช |
|---|---|
getProjPref(string) |
ํํ ํ๋ฆฌํน ๋ก๋ (Resources/Projectiles/) |
getAudioClip(string) |
๋ฌด๊ธฐ ๋ฐ์ฌ ์ค๋์ค ๋ก๋ (Resources/Audio/SFX/Weapons/) |
getAnimator() |
์๊ธฐ ์์ ๋๋ ๋ถ๋ชจ์์ Animator ํ์ |
getSpriteSheet(string) |
์คํ๋ผ์ดํธ ์ํธ ์ ์ฒด ๋ก๋ (Resources/Sprites/) |
getSpriteFromSheet(Sprite[], string) |
์ํธ์์ ํน์ ์คํ๋ผ์ดํธ ์ถ์ถ |
getObject(string) |
๊ฒฝ๋ก ๊ธฐ๋ฐ GameObject ๋ก๋ |
createPSp(...) |
Projectile ๋ฐ์ฌ ์์น์ฉ Transform ์์ฑ |
createPFX(...) |
ํํฐํด ํ๋ฆฌํน ์ธ์คํด์คํ ๋ฐ ๋นํ์ฑํ ์ํ๋ก ๋ฆฌํด |
createSpriteObject(...) |
์คํ๋ผ์ดํธ๊ฐ ํฌํจ๋ GameObject๋ฅผ ์์ฑํ๊ณ ์ํ๋ ์์น์ ๋ฐฐ์น |
// ๋ฌด๊ธฐ ์ด๊ธฐํ ์
basicProjectilePrefab = getProjPref("pfab_Bullet_Laser_Small_Cyan");
strongProjectilePrefab = getProjPref("pfab_Bullet_Laser_MidSize_Blue");
AudioClip fireSFX = getAudioClip("shotgun_fire.wav");
Sprite[] sprites = getSpriteSheet("Weapons/Weapons_001");
Sprite muzzleSprite = getSpriteFromSheet(sprites, "LaserRifle_Muzzle");
createSpriteObject("Muzzle", muzzleSprite, 10, this, position: new Vector3(0.12f, 0, 0));| ํญ๋ชฉ | Weapon ์ ์ฉ ๋ฐฉ์ | ResourceManager + Addressables |
|---|---|---|
| ์ฌ์ฉ ๋ฒ์ | ๋จ์ผ ํด๋์ค (ex. ๋ฌด๊ธฐ) | ์ ์ฒด ๊ฒ์ ๋ฒ์ (UI, ์บ๋ฆญํฐ ๋ฑ) |
| ๋ฆฌ์์ค ๊ฒฝ๋ก | ์ฝ๋์ ํ๋์ฝ๋ฉ | Addressables ์ฃผ์ ๊ธฐ๋ฐ |
| ์บ์ฑ | ์๋ ๊ด๋ฆฌ | ์๋ ์บ์ฑ ๋ฐ ํด์ ๊ฐ๋ฅ |
| ๋น๋๊ธฐ ์ง์ | โ (Resources.Load) | โ UniTask ๊ธฐ๋ฐ ๋น๋๊ธฐ ์ฒ๋ฆฌ |
| ์ฅ์ | ๋น ๋ฅด๊ณ ์ง๊ด์ , ์์กด์ฑ ์์ | ๋๊ท๋ชจ ํ๋ก์ ํธ์ ์ ํฉ, ์ฌ์ฌ์ฉ์ฑ ๋์ |
- ๋ฌด๊ธฐ ํ๋์์๋ง ์ฌ์ฉํ๋ ๋ฆฌ์์ค:
Weapon.cs๋ด๋ถ ํจ์ ์ฌ์ฉ (๋น ๋ฅด๊ณ ๋จ์ํจ) - ์ฌ๋ฌ ์์คํ
์์ ๊ณต์ ๋๋ ๋ฆฌ์์ค:
ResourceManager์ Addressables๋ฅผ ํตํด ๊ด๋ฆฌ (ํ์ฅ์ฑ๊ณผ ์ ์ง๋ณด์ ์ฐ์)
- ์ด ํจ์๋ค์ ๋ชจ๋
protected๋ก ์ ์ธ๋์ด ์์ด, ํ์ ๋ฌด๊ธฐ ํด๋์ค์์ ๋ฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅ Resources.Load()๊ธฐ๋ฐ์ด๋ฏ๋ก ๊ฒฝ๋ก ์คํ ์ null ๋ฐํ โ ๋ฐ๋์ ์์ธ ์ฒ๋ฆฌ ํ์- ์ ์ง๋ณด์ ์ค Addressables๋ก ์ ํํ๋ ค๋ฉด
getObject()โGameManager.Resource.Instantiate()๋ฐฉ์์ผ๋ก ๋ณ๊ฒฝ ๊ฐ๋ฅ
์ด ๊ตฌ์กฐ๋ ๋ฌด๊ธฐ์ฒ๋ผ ๋ฆฌ์์ค์ ๋ฒ์๊ฐ ๋ช ํํ๊ณ ํด๋์ค์ ๊ตญํ๋์ด ์๋ ๊ฒฝ์ฐ ๋งค์ฐ ์ ํฉํฉ๋๋ค. ๋ฐ๋ฉด UI, ์บ๋ฆญํฐ, ํจ๊ณผ ๋ฑ ๋ค์ํ ์์คํ ์์ ์ฐธ์กฐ๋๋ ๋ฆฌ์์ค๋ ResourceManager๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ด ์ด์์ ์ ๋๋ค.
Weapon_ShotGun์ ๊ธฐ์กด ๋ฌด๊ธฐ ์์คํ
(Weapon)์ ์์ํ์ฌ, ํ ๋ฒ์ ์ฌ๋ฌ ๋ฐ์ ํํ์ ํผ๋จ๋ฆฌ๋ ์ท๊ฑด ๊ณ์ด ๋ฌด๊ธฐ๋ฅผ ๊ตฌํํ๊ธฐ ์ํ ๊ธฐ์ด ํด๋์ค์
๋๋ค. ๊ธฐ๋ณธ ๊ณต๊ฒฉ/๊ฐํ ๊ณต๊ฒฉ ๋ชจ๋ ๋คํ ๋ฐ์ฌ๋ฅผ ์ง์ํ๋ฉฐ, ๋ฐ์ฌ ๊ฐ๊ฒฉ๊ณผ ํํ ๊ฐ์ ์ค์ ์ด ๊ฐ๊ฐ ๋ถ๋ฆฌ๋์ด ์์ต๋๋ค.
FINAL_Weapon_LaserShotGun์ ์ด๋ฅผ ์์ํ์ฌ ์ค์ ๊ตฌํ๋ ์ท๊ฑด ๋ฌด๊ธฐ๋ก, ์คํ๋ผ์ดํธ ์ค์ ๋ฐ ๋ฐ์ฌ ์์น, ํํ ํ๋ฆฌํน์ ์ด๊ธฐํํฉ๋๋ค.
| ๊ณต๊ฒฉ ์ ํ | ๋ฐ์ฌ ํํ ์ | ๋ฐ์ฌ ๊ฐ๊ฒฉ (์ด) |
|---|---|---|
| ์ผ๋ฐ ๊ณต๊ฒฉ | 4๋ฐ | 0.5์ด |
| ๊ฐํ ๊ณต๊ฒฉ | 8๋ฐ | 1.0์ด |
- ๊ฐ ํํ์ ๋๋ค ํ์ ๊ฐ๋์ ์๋๋ฅผ ์ ์ฉํ์ฌ ํผ์ง๋ ํํ๋ก ๋ฐ์ฌ๋จ
protected override void PrimaryFire(bool isRight)
{
for (int i = 0; i < 4; i++)
{
GameObject bullet = PhotonNetwork.Instantiate("Projectiles/" + basicProjectilePrefab.name,
projectileSpawnPoint.position, projectileSpawnPoint.rotation);
Projectile proj = bullet.GetComponent<Projectile>();
proj.Speed = 20f * Random.Range(0.9f, 1.1f);
proj.setVolume(2f / 3);
proj.isRPCFire = (PhotonNetwork.InRoom && PhotonManager._currentPhase == PhotonManager.GamePhase.InGame);
proj.Fire(Random.Range(-10f, 10f), isRight);
}
}๋ณธ ์์คํ
์ ํ๋ ์ด์ด๊ฐ F ํค๋ฅผ ๋๋ฌ ๋ฐ๋ฅ์ ๋จ์ด์ง ๋ฌด๊ธฐ ์์ดํ
๊ณผ ํ์ฌ ์ฅ๋น ์ค์ธ ๋ฌด๊ธฐ๋ฅผ ๊ต์ฒดํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
๊ธฐ์กด ์คํ์์ค ๊ตฌ์กฐ์ ํฌํจ๋ TadaInput, PlayerController, WeaponHandler ํด๋์ค๋ค์ ๊ทธ๋๋ก ํ์ฉํ์ฌ ๊ตฌํ๋ฉ๋๋ค.
F ํค๋ TadaInput.ThisKey.GetItem์ผ๋ก ์ง์ ํ์ฌ ๋ฑ๋กํ ์ ์์ต๋๋ค.
if (Input.GetKeyDown(KeyCode.F))
StoreCurrentKeyDown(ThisKey.GetItem);๋ฑ๋ก๋ ํค๋ ์
๋ ฅ์ด ํ์ํ ์์น (์: PlayerController)์์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํฉ๋๋ค:
if (TadaInput.GetKeyDown(TadaInput.ThisKey.GetItem))
{
GameObject obj = _PlayerPhysics.getCollidedObject();
if (obj != null)
{
Item item = obj.GetComponent<Item>();
if (item != null)
{
_WeaponHandler.GetItemWeapon(item);
}
}
}- ํ๋ ์ด์ด๊ฐ ์ถฉ๋ํ ์ค๋ธ์ ํธ๊ฐ
Item์ผ ๊ฒฝ์ฐ์๋ง ์ํธ์์ฉ ์คํ WeaponHandler๋ฅผ ํตํด ๋ฌด๊ธฐ ์ค์ ์ฒ๋ฆฌ
public void GetItemWeapon(Item item)
{
Weapon now = currentWeapon;
Weapon get = item.weapon;
weapons[currentWeaponIndex] = get;
currentWeapon = get;
get.transform.SetParent(now.transform.parent, false);
now.transform.SetParent(item.transform, false);
item.weapon = now;
get.reload();
now.stop();
}- ํ์ฌ ์ฅ๋น ๋ฌด๊ธฐ์ ์์ดํ ๋ฌด๊ธฐ๋ฅผ ์๋ก ๊ต์ฒด
Transform๋ถ๋ชจ๋ฅผ ๋ณ๊ฒฝํ์ฌ ์์น ์๊ฐ์ ์ผ๋ก ์กฐ์ - ์ ๋ฌด๊ธฐ๋
reload(), ๊ธฐ์กด ๋ฌด๊ธฐ๋stop()์ ํธ์ถํ์ฌ ๋ฌด๊ธฐ ์ํ๋ฅผ ์ด๊ธฐํ
| ํญ๋ชฉ | ์ค๋ช |
|---|---|
| ์ ๋ ฅ ํค | F ํค (TadaInput.ThisKey.GetItem) |
| ์ถฉ๋ ๊ฐ์ง | PlayerPhysics.getCollidedObject() ์ฌ์ฉ |
| ์ํธ์์ฉ ๋์ | Item ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ง ์ค๋ธ์ ํธ |
| ์ฒ๋ฆฌ ๋ฐฉ์ | WeaponHandler๋ฅผ ํตํด ๋ฌด๊ธฐ ๊ฐ์ฒด ๊ฐ ์ค์ |
๋ณธ ๊ตฌ์กฐ๋ ์ง๊ด์ ์ธ ์ํธ์์ฉ ํ๋ฆ์ ์ ๊ณตํ๋ฉฐ, ํ์ฅ ์ ๋ค์ํ ์์ดํ ์ข ๋ฅ(์ฒด๋ ฅ, ๋ฐฉ์ด๊ตฌ, ๊ธฐํ ์๋น ์์ดํ ๋ฑ)๋ก๋ ์ฐ๊ณํ ์ ์์ต๋๋ค.