๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

 

 

 

๋กœ๊ทธ๋ผ์ดํฌ ๊ฒŒ์ž„์ด๋‹ˆ, ๋ฌด๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชฌ์Šคํ„ฐ๋“ค์„ ๋•Œ๋ ค์žก์„ ์ˆ˜ ์žˆ์–ด์•ผ ํ•  ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋งŒํผ ๋ฌด๊ธฐ๋ผ๋Š” ๊ฒƒ์ด ์šฐ๋ฆฌ ๊ฒŒ์ž„์—์„œ ํ•ต์‹ฌ์ด ๋œ๋‹ค๋Š” ์–˜๊ธฐ์ฃ . ์šฐ์„  ์šฐ๋ฆฌ ๊ฒŒ์ž„์˜ ๊ธฐ๋ณธ ๋ฌด๊ธฐ์ธ "์นด๋ก ์˜ ๋…ธ(Charon's Paddle)"๋กœ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด๋ณผ ๊ฒ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ๊ทธ ๊ธฐ๋ฐ˜๋งŒ ๋จผ์ € ๋‹ค์ ธ๋ณผ๊นŒ ํ•ด์š”!

 

"์นด๋ก ์˜ ๋…ธ"๋ฅผ ์ฅ๊ณ  ์žˆ๋Š” ์†๋Œ

 

์†”์งํžˆ ๋งํ•ด์„œ ๋ฌด๊ธฐ๊ฐ€ ๋…ธ์ฒ˜๋Ÿผ ์ƒ๊ธฐ์ง„ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๊ตฌ๋งคํ–ˆ๋˜ ๋ฌด๊ธฐ ์—์…‹ ์ค‘์— ๊ทธ๋‚˜๋งˆ ๋…ธ ๊ฐ™์ด ์ƒ๊ธด ๊ฑธ๋กœ ์ฅ์–ด ์ฃผ์—ˆ์–ด์š”...

๊ทธ๋ฆฌ๊ณ  ๊ฒŒ์ž„ ๊ทธ๋ž˜ํ”ฝ์ด ๋„ˆ๋ฌด ๋ฐ‹๋ฐ‹ํ•œ ๊ฒƒ ๊ฐ™์•„์„œ URP(Universal Render Pipeline)์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์—…๊ทธ๋ ˆ์ด๋“œ ํ•˜๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ, ์ปค์Šคํ…€ ์‰์ด๋”(Custom shader)๋Š” URP Shader๋กœ ์ž๋™ ๋ณ€ํ™˜์ด ์•ˆ ๋˜๋”๋ผ๊ตฌ์š”.

 

ํ˜„์žฌ ๊ตฌ์ž…ํ–ˆ๋˜ ์—์…‹ ์ค‘์— ๋ฌผ๊ณผ ๊ฒ€๊ธฐ ์ดํŽ™ํŠธ ์—์…‹์ด ์ปค์Šคํ…œ ์‰์ด๋”๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์‰์ด๋”์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด ๋ณธ ์ ์ด ์•„์ง ์—†๊ธฐ ๋•Œ๋ฌธ์— ์‰์ด๋” ์žฌ์ž‘์„ฑ์€ ๋ฌด๋ฆฌ๋ผ ์ƒ๊ฐํ•˜์—ฌ ์ง€๊ธˆ ๊ทธ๋Œ€๋กœ ์ง„ํ–‰ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค... ๋‹ค์Œ ๊ฒŒ์ž„์€ ์–ธ๋ฆฌ์–ผ ์—”์ง„(Unreal Engine)์œผ๋กœ ๋งŒ๋“ค์–ด ๋ด์•ผ ๊ฒ ์–ด์š”...

 

๊ทธ๋Ÿผ ์ด๋ฒˆ ์ฃผ์— ์ œ๊ฐ€ ๋ฌด๊ธฐ ์‹œ์Šคํ…œ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ๊ธฐ๋ฐ˜์„ ๋จผ์ € ๋‹ค์กŒ๋Š”์ง€, ์–ด๋– ํ•œ ๋ฌธ์ œ๋“ค์„ ๊ฒช์—ˆ๋Š”์ง€ ์„ค๋ช…์„ ๋“œ๋ฆฌ๋„๋ก ํ• ๊ฒŒ์š”!

 

 

 


1. ๊ณต๊ฒฉ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ˆ˜์ •ํ•˜๊ธฐ

 

ํœด๋จธ๋…ธ์ด๋“œ ์• ๋‹ˆ๋ฉ”์ด์…˜(Humanoid Animation)์˜ ๋ฌธ์ œ์ 

 

์นด๋ก ์˜ ๋…ธ ๊ธฐ๋ณธ ๊ณต๊ฒฉ์€ ์ด 3๊ฐ€์ง€ ์ฝค๋ณด๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ผ์ • ์‹œ๊ฐ„ ๋‚ด์— ๊ณต๊ฒฉ ์ปค๋งจ๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋‹ค์Œ ์ฝค๋ณด๋กœ ์ด์–ด๊ฐ€๊ณ , ์•„๋‹ˆ๋ผ๋ฉด ์ฒ˜์Œ ๊ณต๊ฒฉ์œผ๋กœ ์ดˆ๊ธฐํ™” ๋˜๋Š” ๋ฐฉ์‹์ด์ฃ .

*์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์ž˜๋ชป ๊ฑด๋“œ๋ ธ๋Š”์ง„ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ, ์‹คํ–‰ํ•˜๋ฉด ์ž๊พธ ํฌํ•œํ•œ ๊ณณ์œผ๋กœ ์œ„์น˜ ์ด๋™ํ•˜์—ฌ ์žฌ์ƒํ•˜๋”๋ผ๊ตฌ์š”... ๊ทธ๋ž˜๋„ ์ธ๊ฒŒ์ž„์—์„œ๋Š” ์ •์ƒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

 

1ํƒ€ ๊ณต๊ฒฉ (ํœ˜๋‘๋ฅด๊ธฐ)
2ํƒ€ ๊ณต๊ฒฉ(๋‚ด๋ ค์ฐ๊ธฐ)
3ํƒ€ ๊ณต๊ฒฉ(์ฐŒ๋ฅด๊ธฐ)

 

์—ฌ๊ธฐ์— ์ด์ œ ์†๋Œ์˜ ์†์—๋‹ค ๋ฌด๊ธฐ๋ฅผ ์ฅ์–ด์ฃผ๊ณ , ์‹คํ–‰๋งŒ ํ•˜๋ฉด ๋ชจ๋“  ๊ฒŒ ์ž˜ ๋  ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ธ์ƒ์€ ๊ทธ๋ ‡๊ฒŒ ์‰ฌ์šด ๊ฒƒ์ด ์•„๋‹ˆ์ฃ ...

 

๋„ˆ ์–ด๋””๋กœ ๋‚ด๋ ค ์ฐ๋Š”๊ฑฐ์•ผ... ๋ฌด๊ธฐ๋Š” ์™œ ๋˜ ๋ชฉ์„ ์ฐŒ๋ฅด๊ณ  ์žˆ์–ด
์ฐŒ๋ฅด๊ธด ์ฐŒ๋ฅด๋Š”๋ฐ, ๋ฌด๊ธฐ๊ฐ€ ์–ด๋”œ ํ–ฅํ•˜๋‹ˆ?,,,

 

์•„์ฃผ ๋‚œ๋ฆฌ๊ฐ€ ๋‚œ ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์• ๋‹ˆ๋ฉ”์ด์…˜ ํ‚ค ํ”„๋ ˆ์ž„์„ ์ˆ˜์ •ํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™๋„ค์š”.

ํ•˜์ง€๋งŒ ํœด๋จธ๋…ธ์ด๋“œ ์• ๋‹ˆ๋ฉ”์ด์…˜์€ Unity ๋‚ด์—์„œ ํ‚ค ํ”„๋ ˆ์ž„ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์—ˆ๋˜ ์™ธ๋ถ€ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ˆ˜์ •ํ•˜์—ฌ ๋‹ค์‹œ Unity๋กœ ์ž„ํฌํŠธ ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•ด์š”.

 

 

๊ทธ๋Ÿฌ๋ฉด ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์„ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด ์ฃผ์ž!

 

์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค ๋‹น์‹œ์— ์‚ฌ์šฉ๋˜์—ˆ๋˜ ์†๋Œ์˜ ์‹ ์ฒด๋“ค์„ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์ด์ง€, ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•œ ๊ฒƒ์€ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ•œ๋‹ค๊ณ ๋Š” ์•ˆ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ๊ฑฐ์ณค์ฃ .

 

  • ๋นˆ ์˜ค๋ธŒ์ ํŠธ(HandleWeaponPosition)์„ ์ƒ์„ฑํ•˜์—ฌ, ์†๋Œ์˜ ์†(RightHand)๊ณผ ๋‚˜๋ž€ํžˆ ๋‘”๋‹ค.
  • ์†๋Œ์˜ ์†(RightHand) ํŠธ๋žœ์Šคํผ ๊ฐ’์„ ๋นˆ ์˜ค๋ธŒ์ ํŠธ(HandleWeaponPosition)์˜ ํŠธ๋žœ์Šคํผ์— ๋ณต๋ถ™ํ•œ๋‹ค.
    • ์ฆ‰, ์ƒˆ๋กœ ์ƒ์„ฑํ•œ ๋นˆ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋ฌด๊ธฐ๋ฅผ ์ฅ๋Š” ์†๋Œ์˜ ์† ์—ญํ• ์„ ํ•ด์ค„ ๊ฒ๋‹ˆ๋‹ค.
  • ์•ž์œผ๋กœ ๊ฐ ๋ฌด๊ธฐ๋“ค์€ ์ด ๋นˆ ์˜ค๋ธŒ์ ํŠธ(HandleWeaponPosition) ์ž์‹ ์˜ค๋ธŒ์ ํŠธ๋กœ ๋ฐฐ์น˜ํ•œ๋‹ค.

 

๊ณ„์ธต๊ตฌ์กฐ

 

์ƒˆ๋กœ ๋งŒ๋“  ์ € ๋นˆ ์˜ค๋ธŒ์ ํŠธ(HandleWeaponPosition)์œผ๋กœ ํ‚ค ํ”„๋ ˆ์ž„์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๊ฐ ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ๋ฌด๊ธฐ ๋ฐฐ์น˜๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ๋„๋ก ํ•ฉ์‹œ๋‹ค. ๊ฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ํ‚ค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๋ฌด๊ธฐ๊ฐ€ ์ด์ƒํ•œ ๊ฐ๋„๋กœ ๋“ค๋ ค ์žˆ๊ฑฐ๋‚˜, ์ด์ƒํ•œ ๊ณณ์— ์žˆ์œผ๋ฉด ์ˆ˜์ •ํ•ด์ฃผ๋ฉด ๋ผ์š”!

 

๊ดœ์ฐฎ์€ ๊ผผ์ˆ˜์ด์ง€ ์•Š์Šต๋‹ˆ๊นŒ?
[์• ๋‹ˆ๋ฉ”์ด์…˜ ์ˆ˜์ • ํ›„ 1ํƒ€ ๊ณต๊ฒฉ(ํœ˜๋‘๋ฅด๊ธฐ)] ์‹ธ๋Œ€๊ธฐ ์ž˜ ๋•Œ๋ฆฌ๋„ค์š”!
์• ๋‹ˆ๋ฉ”์ด์…˜ ์ˆ˜์ • ํ›„ 2ํƒ€ ๊ณต๊ฒฉ(๋‚ด๋ ค์ฐ๊ธฐ)
์• ๋‹ˆ๋ฉ”์ด์…˜ ์ˆ˜์ • ํ›„ 3ํƒ€ ๊ณต๊ฒฉ(์ฐŒ๋ฅด๊ธฐ)

 

์• ๋‹ˆ๋ฉ”์ด์…˜์— ๋Œ€ํ•œ ์ˆ˜์ • ์ž‘์—…์€ ๋๋‚ฌ๋„ค์š”! ์ด์ œ ๋ฌด๊ธฐ ํƒˆ์žฅ์ฐฉ ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค์–ด ๋ณด์ฃ .

 

 

 


2. ๋ฌด๊ธฐ ํƒˆ์žฅ์ฐฉ ์‹œ์Šคํ…œ ์„ค๊ณ„ํ•˜๊ธฐ

 

๊ฒŒ์ž„์˜ ๊ทœ๋ชจ์— ๋”ฐ๋ผ ๋ฌด๊ธฐ ์ข…๋ฅ˜๋Š” ๊ต‰์žฅํžˆ ๋งŽ์„ ์ˆ˜๋„, ์ ์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฉ”์ดํ”Œ์Šคํ† ๋ฆฌ ๊ฐ™์€ ๊ฒฝ์šฐ๋งŒ ๋ณด๋”๋ผ๋„ ๋ฌด๊ธฐ๊ฐ€ ๊ต‰์žฅํžˆ ๋งŽ์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์ฃ . ๊ฒŒ์ž„ ๋‚ด์— ์žˆ๋Š” ๋ชจ๋“  ๋ฌด๊ธฐ ์ข…๋ฅ˜๋ฅผ ์ฝ์–ด ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๋Š” ๊ฒƒ๋„ ๋ญ”๊ฐ€ ๋‚ญ๋น„์ธ ๋Š๋‚Œ์ž…๋‹ˆ๋‹ค.

 

๊ทธ๋ž˜์„œ ์ œ๊ฐ€ ์ƒ๊ฐํ•œ ๊ฒƒ์€ ์œ ์ €์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฌด๊ธฐ ๋ชฉ๋ก๋“ค๋งŒ ๊ฐ€์ ธ์™€์„œ ์˜ฌ๋ฆฌ์ž๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์šฐ๋ฆฌ ๊ฒŒ์ž„์—์„œ๋Š” ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ฌด๊ธฐ ๊ต์ฒด๋Š” ํ•˜์ง€ ๋ชป ํ•˜๊ณ , ๋กœ๋น„์—์„œ๋งŒ ๋ฌด๊ธฐ ๊ต์ฒด๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ฒ˜์Œ ํ”Œ๋ ˆ์ด ํ•  ๋•Œ๋Š” ์นด๋ก ์˜ ๋…ธ ๋ฐ–์— ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ฒ ์ง€๋งŒ, ํ”Œ๋ ˆ์ด ํ•˜๋ฉฐ ์‹œ๊ฐ„์ด ์ง€๋‚˜ ๋‹ค๋ฅธ ๋ฌด๊ธฐ ์‚ฌ์šฉ ์กฐ๊ฑด๋“ค์„ ์ถฉ์กฑํ•œ๋‹ค๋ฉด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌด๊ธฐ ์ข…๋ฅ˜๋“ค์ด ๋Š˜์–ด ๊ฐ€๊ฒ ์ฃ .

 

DB๋‚˜ ๊ธฐํƒ€ ์ €์žฅ์†Œ์—๋Š” ํ•ด๋‹น ์œ ์ €๊ฐ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฌด๊ธฐ์˜ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•  ๊ฒ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํŠน์ • ์ƒํ™ฉ์ด ๋˜๋ฉด ํ•ด๋‹น ๋ฌด๊ธฐ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ๋กœ ์ฝ์–ด์˜ค๋Š” ๊ฒƒ์ด์ฃ . ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๋Š” ํŠน์ • ์ƒํ™ฉ์ด๋ผ ํ•จ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

  • ๊ฒŒ์ž„์„ ์ฒ˜์Œ ์‹คํ–‰ํ•˜๋Š” ์ดˆ๊ธฐํ™” ๋‹จ๊ณ„์—์„œ ์œ ์ €๊ฐ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ–ˆ๋˜ ๋ฌด๊ธฐ ๋ชฉ๋ก๋“ค์„ ์ฝ์–ด์˜ฌ ๋•Œ
  • ๊ฒŒ์ž„ ์ค‘, ์ƒˆ๋กœ์šด ๋ฌด๊ธฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์„ ๋•Œ

 

 

๋ฌผ๋ก  ์ €์žฅ/๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์‹œ์Šคํ…œ์„ ์ œ๊ฐ€ ๋‹ด๋‹นํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ์—, ํ•ด๋‹น ํŒŒํŠธ๋ฅผ ๋งก์€ ๋‹ค๋ฅธ ํŒ€์›๊ณผ๋„ ์ƒ์˜๋ฅผ ํ–ˆ์ง€์š”. ์ด๊ฑธ ํ† ๋Œ€๋กœ ์šฐ์„  ์ž„์‹œ ํ…Œ์ŠคํŠธ์šฉ์„ ๋งŒ๋“ค์–ด ๋ณผ ๊ฒ๋‹ˆ๋‹ค. ํ•˜๋‚˜์”ฉ ์ œ๊ฐ€ ํ–ˆ๋˜ ์ˆœ์„œ๋Œ€๋กœ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

Scriptable Object๋กœ ๋ฌด๊ธฐ๋ฅผ ์ฅ๋Š” ๋กœ์ปฌ ์ขŒํ‘œ ์ •๋ณด ์ €์žฅํ•˜๊ธฐ

 

๋ฌด๊ธฐ ์ข…๋ฅ˜๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€์ผ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ์บ๋ฆญํ„ฐ๊ฐ€ ๋ชจ๋“  ๋ฌด๊ธฐ๋ฅผ ์ฅ๋Š” ๋ฐฉ๋ฒ•์ด ์ „๋ถ€ ๋‹ค๋ฅด์ง€๋Š” ์•Š์„ ๊ฒ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ๋ฌด๊ธฐ๋“ค์ด ์žˆ๋”๋ผ๋„ ๊ทธ ๋ฌด๊ธฐ๋“ค์ด ํ•œ์† ๋ฌด๊ธฐ ํƒ€์ž…์ด๋ฉด, ์บ๋ฆญํ„ฐ๋Š” ํ•ด๋‹น ๋ฌด๊ธฐ๋“ค์„ ์ฅ˜ ๋•Œ ํ•œ ์†์œผ๋กœ๋งŒ ์ฅ˜ ๊ฒ๋‹ˆ๋‹ค.

์ฆ‰, ์ฅ๋Š” ๋ฐฉ๋ฒ•์ด ๊ณตํ†ต์ ์ธ ๋ฌด๊ธฐ๋“ค๋„ ๋งŽ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ ์„ ๋ฏธ๋ฃจ์–ด ๋ณด์•˜์„ ๋•Œ, ์Šคํฌ๋ฆฝํ„ฐ๋ธ” ์˜ค๋ธŒ์ ํŠธ(Scriptable Object)๋กœ ๊ด€๋ฆฌํ•˜๋ฉด ๊ต‰์žฅํžˆ ํŽธํ•˜๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "Weapon Handle Data", menuName = "Scriptable Object/Weapon Handle Data", order = int.MaxValue)]
public class WeaponHandleData : ScriptableObject
{
    public Vector3 localPosition;
    public Vector3 localRotation;
    public Vector3 localScale;
}

 

๋ฌด๊ธฐ๋Š” ์†์˜ ์ž์‹ ์˜ค๋ธŒ์ ํŠธ๋กœ ๋ฐฐ์น˜๋˜๊ธฐ ๋•Œ๋ฌธ์—, ์›”๋“œ ์ขŒํ‘œ๊ฐ€ ์•„๋‹Œ ๋กœ์ปฌ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฑธ ํ† ๋Œ€๋กœ ์นด๋ก ์˜ ๋…ธ๋ฅผ ์ฅ˜ ๋•Œ์˜ ๋กœ์ปฌ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

์นด๋ก ์˜ ๋…ธ๋ฅผ ์žก๋Š” ๋กœ์ปฌ ์œ„์น˜ ์Šคํฌ๋ฆฝํ„ฐ๋ธ” ์˜ค๋ธŒ์ ํŠธ

 

์‹ค์ œ๋กœ ์บ๋ฆญํ„ฐ์— ์ฅ์–ด๋ณด๊ฒŒ ํ•œ ํ›„์— ํŠธ๋žœ์Šคํผ(Transform)์„ ๋ณด๋‹ˆ, ์œ„์™€ ๊ฐ™๋”๊ตฐ์š”. ๊ทธ๋ž˜์„œ ํ•ด๋‹น ์ •๋ณด๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์–ด ์คฌ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์‹ค์ œ ๋ฌด๊ธฐ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค.

 

 

๋ฌด๊ธฐ ํด๋ž˜์Šค์™€ ๋ฌด๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค ์ •์˜ํ•˜๊ธฐ

 

๋ชจ๋“  ๋ฌด๊ธฐ๋“ค์˜ ๊ณตํ†ต์ ์ธ ๋ถ€๋ถ„๋“ค์„ ๋ชจ์•„์„œ, ์ถ”์ƒ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

using CharacterController;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public abstract class BaseWeapon : MonoBehaviour
{
    // ๋ฌด๊ธฐ์˜ ํ˜„์žฌ ์ฝค๋ณด ์นด์šดํŠธ
    public int ComboCount { get; set; }
    // ์ด ๋ฌด๊ธฐ๋ฅผ ์ฅ˜ ๋•Œ์˜ ๋กœ์ปฌ ์ขŒํ‘œ ์ •๋ณด
    public WeaponHandleData HandleData { get { return weaponhandleData; } }
    // ์ด ๋ฌด๊ธฐ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ์˜ ์• ๋‹ˆ๋ฉ”์ดํ„ฐ
    public RuntimeAnimatorController WeaponAnimator { get { return weaponAnimator; } }
    public string Name { get { return _name; } }
    public float AttackDamage { get { return attackDamage; } }
    public float AttackSpeed { get { return attackSpeed; } }
    public float AttackRange { get { return attackRange; } }

    #region #๋ฌด๊ธฐ ์ •๋ณด
    [Header("์ƒ์„ฑ ์ •๋ณด"), Tooltip("ํ•ด๋‹น ๋ฌด๊ธฐ๋ฅผ ์ฅ์—ˆ์„ ๋•Œ์˜ Local Transform ๊ฐ’ ์ •๋ณด์ž…๋‹ˆ๋‹ค.")]
    [SerializeField] protected WeaponHandleData weaponhandleData;

    [Header("๋ฌด๊ธฐ ์ •๋ณด")]
    [SerializeField] protected RuntimeAnimatorController weaponAnimator;
    [SerializeField] protected string _name;
    [SerializeField] protected float attackDamage;
    [SerializeField] protected float attackSpeed;
    [SerializeField] protected float attackRange;
    #endregion

    public void SetWeaponData(string name, float attackDamage, float attackSpeed, float attackRange)
    {
        this._name = name;
        this.attackDamage = attackDamage;
        this.attackSpeed = attackSpeed;
        this.attackRange = attackRange;
    }

    public abstract void Attack(BaseState state);         // ๊ธฐ๋ณธ ๊ณต๊ฒฉ
    public abstract void DashAttack(BaseState state);     // ๋Œ€์‹œ ๊ณต๊ฒฉ
    public abstract void ChargingAttack(BaseState state); // ์ฐจ์ง€ ๊ณต๊ฒฉ
    public abstract void Skill(BaseState state);          // ์Šคํ‚ฌ
    public abstract void UltimateSkill(BaseState state);  // ๊ถ๊ทน๊ธฐ
}

 

๊ทธ๋ ‡๋‹ค๋ฉด, ์ด๋Ÿฌํ•œ ๋ฌด๊ธฐ๋“ค์„ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ํด๋ž˜์Šค๋„ ํ•„์š”ํ•  ๊ฒ๋‹ˆ๋‹ค.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponManager
{
    // ํ˜„์žฌ ๋ฌด๊ธฐ ์Šคํฌ๋ฆฝํŠธ
    public BaseWeapon Weapon { get; private set; }
    // ์ด ๋ถ€๋ถ„์€ ํฌ๊ฒŒ ์‹ ๊ฒฝ ์•ˆ ์“ฐ์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
    public Action<GameObject> unRegisterWeapon { get; set; }
    // ๋ฌด๊ธฐ๋ฅผ ์ฅ๋Š” ์†์˜ ํŠธ๋žœ์Šคํผ
    private Transform handPosition;
    // ํ˜„์žฌ ๋‚ด ๋ฌด๊ธฐ ์˜ค๋ธŒ์ ํŠธ
    private GameObject weaponObject;
    // ํ˜„์žฌ WeaponManager์— ๋“ฑ๋ก๋œ ๋ฌด๊ธฐ ๋ฆฌ์ŠคํŠธ
    private List<GameObject> weapons = new List<GameObject>();
  
    public WeaponManager(Transform hand)
    {
        handPosition = hand;
    }

    // ๋ฌด๊ธฐ ๋“ฑ๋ก
    public void RegisterWeapon(GameObject weapon)
    {
        if (!weapons.Contains(weapon))
        {
            BaseWeapon weaponInfo = weapon.GetComponent<BaseWeapon>();
            weapon.transform.SetParent(handPosition);
            weapon.transform.localPosition = weaponInfo.HandleData.localPosition;
            weapon.transform.localEulerAngles = weaponInfo.HandleData.localRotation;
            weapon.transform.localScale = weaponInfo.HandleData.localScale;
            weapons.Add(weapon);
            weapon.SetActive(false);
        }
    }
    
    // ๋ฌด๊ธฐ ์‚ญ์ œ
    public void UnRegisterWeapon(GameObject weapon)
    {
        if (weapons.Contains(weapon))
        {
            weapons.Remove(weapon);
            unRegisterWeapon.Invoke(weapon);
        }
    }

    // ๋ฌด๊ธฐ ๋ณ€๊ฒฝ
    public void SetWeapon(GameObject weapon)
    {
        if (Weapon == null)
        {
            weaponObject = weapon;
            Weapon = weapon.GetComponent<BaseWeapon>();
            weaponObject.SetActive(true);
            Player.Instance.animator.runtimeAnimatorController = Weapon.WeaponAnimator;
            return;
        }

        for(int i = 0; i < weapons.Count; i++)
        {
            if (weapons[i].Equals(Weapon))
            {
                weaponObject = weapon;
                weaponObject.SetActive(true);
                Weapon = weapon.GetComponent<BaseWeapon>();
                Player.Instance.animator.runtimeAnimatorController = Weapon.WeaponAnimator;
                continue;
            }
            weapons[i].SetActive(false);
        }
    }
}

 

์ฝ”๋“œ๊ฐ€ ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ต์ง„ ์•Š์„ ๊ฑฐ๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ํ˜„์žฌ ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ๋ฌด๊ธฐ๋งŒ ํ™œ์„ฑํ™” ๋˜์–ด์žˆ๊ณ , ๋‚˜๋จธ์ง€ ๋ฌด๊ธฐ๋“ค์€ ๋น„ํ™œ์„ฑํ™”๋œ ์ฑ„๋กœ ์ฅ๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์ด ํ•ต์‹ฌ์ด ๋˜๊ฒ ๋„ค์š”. WeaponManager ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์—ˆ์œผ๋‹ˆ, Player ์Šคํฌ๋ฆฝํŠธ์— ์„ ์–ธํ•ด์ฃผ๋„๋ก ํ•ฉ์‹œ๋‹ค.

 

๋…ธ๋ž€์ƒ‰ ์น ํ•œ ๋ถ€๋ถ„๋งŒ ๋ณด๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ๋ถ€๋ถ„์ด์—์š”.
์šฐ๋ฆฌ๊ฐ€ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ˆ˜์ •ํ•œ๋‹ค๊ณ  ๋งŒ๋“ค์—ˆ๋˜ ์˜ค๋ธŒ์ ํŠธ ์žˆ์ฃ ? ๊ทธ๊ฑธ ๋„ฃ์–ด์ค์‹œ๋‹ค.

 

์ด์ œ ์ž„์‹œ๋กœ ํ•œ ๋ฒˆ ํ…Œ์ŠคํŠธํ•ด๋ณด๋„๋ก ํ•˜์ฃ . ๋นˆ ์˜ค๋ธŒ์ ํŠธ์— ์ธ๋ฒคํ† ๋ฆฌ ๋งค๋‹ˆ์ € ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ, ์นด๋ก ์˜ ๋…ธ ๋ฌด๊ธฐ๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ๋ด…์‹œ๋‹ค.

 

*์ƒˆ๋กœ์šด ๋ฌด๊ธฐ๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•  ๋•Œ์— ๊ฐฑ์‹ ๋˜๋Š” ์ฝ”๋“œ ๋ถ€๋ถ„์€ ์ž‘์„ฑํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๋‚˜์ค‘์— ์ง„ํ–‰์ด ๋” ๋˜๋ฉด ๊ทธ๋•Œ ๋งŒ๋“ค๋ ค๊ตฌ์š”!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InventoryManager : MonoBehaviour
{
    public static InventoryManager Instance { get; private set; }
    private static InventoryManager instance;
    public GameObject charonPaddle;  /// ํ…Œ์ŠคํŠธ์šฉ ์นด๋ก ์˜ ๋…ธ

    void Awake()
    {
        if(instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
            return;
        }
        DestroyImmediate(gameObject);
    }

    void Start()
    {
        Init();
    }


    private void Init()   /// ๊ฒŒ์ž„ ์‹œ์ž‘ ํ›„ ์œ ์ €์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฌด๊ธฐ๋ฅผ ์ฝ์–ด์˜ค๋Š” ์ดˆ๊ธฐํ™” ๋ฉ”์†Œ๋“œ
    {
        /* 
           ---------์Šˆ๋„ ์ฝ”๋“œ---------
           ๋Œ€๊ฐ• ์ด๋Ÿฐ ๋กœ์ง์œผ๋กœ ๋Œ์•„๊ฐ„๋‹ค๊ณ ๋งŒ ์ƒ๊ฐ์„ ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค.
           GameObject[] weapons = Database.LoadWeapons();
           for(int i = 0; i < weapons.Length; i++)
           {
                Player.Instance.weaponManager.RegisterWeapon(weapon[i]);
           }
        */
        
        // ์นด๋ก ์˜ ๋…ธ ํ…Œ์ŠคํŠธ์šฉ
        GameObject weapon = Instantiate(charonPaddle);
        Player.Instance.weaponManager.RegisterWeapon(weapon);
        Player.Instance.weaponManager.SetWeapon(weapon);
    }
}

 

 

์ด์ œ ๊ฒŒ์ž„์„ ์‹คํ–‰ํ•ด๋ณด๋ฉด, ์›๋ž˜ ๋นˆ์†์ด์—ˆ์ง€๋งŒ ์นด๋ก ์˜ ๋…ธ๋ฅผ ์ฅ๊ณ  ์žˆ๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.

 

์ž˜ ์ฅ๊ณ  ์žˆ๋„ค์š”!

 

์ง€๊ธˆ์€ ๋ฌด๊ธฐ๋ฅผ ํ•˜๋‚˜ ๋ฐ–์— ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜์ง€๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฌด๊ธฐ๋“ค์ด ์—ฌ๋Ÿฌ ๊ฐœ์˜€๋‹ค๋ฉด, HandleWeaponPosition ์ž์‹์œผ๋กœ ์ƒ์„ฑ๋˜์—ˆ์„ ๊ฒƒ์ด๊ณ , ํ˜„์žฌ ์‚ฌ์šฉ ์ค‘์ธ ๋ฌด๊ธฐ๋งŒ ํ™œ์„ฑํ™”๊ฐ€ ๋˜์–ด ์žˆ๊ฒ ์ง€์š”. ์ด๋Ÿฐ ๊ธฐ๋ฐ˜์„ ๋งŒ๋“ค์–ด ๋†“์•˜์œผ๋‹ˆ, ์•ž์œผ๋กœ ์ƒˆ๋กœ์šด ๋ฌด๊ธฐ๋ฅผ ๋งŒ๋“ค๊ฒŒ ๋˜๋ฉด, ์—ฌ๊ธฐ์— ๋“ฑ๋กํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋” ์ž‘์„ฑํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ, ๊ธ€์ด ๊ธธ์–ด์งˆ ๊ฒƒ ๊ฐ™์•„์„œ ๋‹ค์Œ ๊ธ€์—์„œ ์จ์•ผํ•  ๊ฒƒ ๊ฐ™๋„ค์š”. ๋‹ค์Œ ๊ธ€์—์„œ๋Š” ๋‹ค์Œ ๋‚ด์šฉ๋“ค์„ ๋‹ค๋ค„๋ณผ๊นŒ ํ•ฉ๋‹ˆ๋‹ค.

  • ์‚ฌ์šฉ์ž์˜ ์—ฌ๋Ÿฌ ๊ณต๊ฒฉ ํ‚ค ์ž…๋ ฅ๋“ค ๋ฐ›์•„ ๋ถ„๊ธฐ ์ฒ˜๋ฆฌํ•˜๊ธฐ
  • ๊ณต๊ฒฉ ์ƒํƒœ(AttackState)๋ฅผ ์ƒํƒœ๋จธ์‹ (StateMachine)์— ์ถ”๊ฐ€ํ•˜๊ธฐ
  • ์นด๋ก ์˜ ๋…ธ ๊ธฐ๋ณธ 3ํƒ€ ๊ณต๊ฒฉ ๊ตฌํ˜„ํ•˜๊ธฐ

 

 

๊ธด ๊ธ€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

728x90
๋ฐ˜์‘ํ˜•