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

 

 

 

1. ์Šคํ”„๋ผ์ดํŠธ ๋ Œ๋”๋Ÿฌ(Sprite Renderer)์˜ Flip ์†์„ฑ ์ด์šฉ

 

Sprite Renderer

 

Flip ์†์„ฑ์„ ํ†ตํ•ด X์ถ•, Y์ถ•, ํ˜น์€ ๋‘˜ ๋‹ค ๋ฐ˜์ „์— ๋Œ€ํ•œ ์ถ•์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ, ๋ Œ๋”๋ง๋งŒ ์˜ํ–ฅ์„ ๋ฐ›๋Š” ๋‹จ์ ์ด ์žˆ๋‹ค.

๋‹ค์Œ์€ 2D Capsule ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜๊ณ , ํ•˜์œ„ ์ž์‹์œผ๋กœ 2D Circle ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์„œ ๋„ฃ์–ด๋†จ๋‹ค.

์บก์Š์€ ์ƒํ•˜์ขŒ์šฐ ๋ชจ๋‘ ๋ฐ˜์ „์— ๋Œ€ํ•ด ๋Œ€์นญ์ด๋ฏ€๋กœ ๊ตฌ๋ถ„์„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ, ๋‹ค๋ฅธ ๋ชจ์–‘์œผ๋กœ Sprite๋ฅผ ๋ฐ”๊ฟ”๋†จ๋‹ค.

 

Flip ์ ์šฉ ์ „

 

X์ถ•์— ๋Œ€ํ•œ Flip ์ ์šฉ

 

Y์ถ•์— ๋Œ€ํ•œ Flip ์ ์šฉ

 

 

์œ ๋‹ˆํ‹ฐ๋ฅผ ํ†ตํ•ด ์œ„์™€ ๊ฐ™์ด ์‹คํ—˜์„ ์ง„ํ–‰ํ–ˆ๋‹ค. ๋ณด๋ฉด ์•Œ๊ฒ ์ง€๋งŒ, 2D Capsule ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ Œ๋”๋ง ๋ถ€๋ถ„๋งŒ ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค.

ํ•˜์œ„ ์ž์‹์œผ๋กœ ์ƒ์„ฑํ–ˆ๋˜ 2D Circle ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋Š” ์•„๋ฌด๋Ÿฐ ์˜ํ–ฅ์ด ์—†๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ, Sprite Renderer์˜ Flip ๊ธฐ๋Šฅ์„ ์ด์šฉํ•  ๋• ์œ„์™€ ๊ฐ™์€ ์ƒํ™ฉ์ด๋ผ๋ฉด ์ฃผ์˜ํ•ด์„œ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์žˆ์–ด ๋ณด์ธ๋‹ค.

 

 

 

2. Transform ์ปดํฌ๋„ŒํŠธ์˜ Scale ๊ฐ’ ๋ถ€ํ˜ธ ๋ฐ”๊พธ๊ธฐ

 

๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋Š” ํŠธ๋žœ์Šคํผ(Transform) ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. (UI๋Š” Rect Transform)

ํŠธ๋žœ์Šคํผ์—์„œ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์˜ ํฌ๊ธฐ ์ •๋ณด๋ฅผ ๋‹ด๋‹นํ•˜๋Š” Scale ๊ฐ’์˜ ๋ถ€ํ˜ธ๋ฅผ ๋ฐ”๊พธ๋Š” ๊ฑธ ํ†ตํ•ด์„œ ๋ฐ˜์ „์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

2D Capsule ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ขŒ์šฐ๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์œ„ ์ž์‹์œผ๋กœ 2D Circle ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋‹ฌ์•„๋†จ๋‹ค.

 

(์ขŒ์šฐ ๋ฐ˜์ „, X์ถ•) Scale ๋ถ€ํ˜ธ ๋ณ€๊ฒฝ ์ „

 

(์ขŒ์šฐ ๋ฐ˜์ „, X์ถ•) Scale ๋ถ€ํ˜ธ ๋ณ€๊ฒฝ ํ›„

 

(์ƒํ•˜ ๋ฐ˜์ „, Y์ถ•) Scale ๋ถ€ํ˜ธ ๋ณ€๊ฒฝ ์ „

 

(์ƒํ•˜ ๋ฐ˜์ „, Y์ถ•) Scale ๋ถ€ํ˜ธ ๋ณ€๊ฒฝ ํ›„

 

 

์Šคํฌ๋ฆฝํŠธ(script) ์ƒ์—์„œ ์ ‘๊ทผํ•˜์—ฌ ์ˆ˜์ •ํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์จ์ฃผ๋ฉด ๋  ๊ฒƒ์ด๋‹ค.

private float scaleX = transform.localSacle.x;
private float scaleX = transform.localSacle.y;
private float scaleX = transform.localSacle.z;

// ์ขŒ์šฐ ๋ฐ˜์ „์ผ ๊ฒฝ์šฐ
transform.localScale = new Vector3(-scaleX, scaleX, scaleX);

// ์ƒํ•˜ ๋ฐ˜์ „์ผ ๊ฒฝ์šฐ
transform.localScale = new Vector3(scaleX, -scaleX, scaleX);

 

2D ๊ฒŒ์ž„ ์บ๋ฆญํ„ฐ๋ฅผ ์ขŒ์šฐ๋กœ ์›€์ง์ด๋‹ค ๋ณด๋ฉด, ๋‹น์—ฐํžˆ ์ง„ํ–‰ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฒŒ์ž„ ์บ๋ฆญํ„ฐ๊ฐ€ ๋ฐ”๋ผ๋ณด๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.

๊ทธ๋Ÿฐ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๋ฉด ์œ ์šฉํ•  ๋“ฏ ํ•˜๋‹ค.

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•