[๐ฌ]
์ ๋ตํจํด์ผ๋ก ๊ฐ๋จํ ์์น์ด๋ ๊ธฐ๋ฅ ๊ตฌํํ๋๊ฑฐ ์ข ๋์์ฃผ์ค๋ถ....ใ
buger81..(211.197)
2022-04-29 03:49
์ถ์ฒ 0
public class Person
{
private IMovestrategy movestrategy
;
private IJumpstrategy jumpstrategy
;
int d
; //์ด๋ํ ๊ฑฐ๋ฆฌ
public Person(IMovestrategy movestrategy
, IJumpstrategy jumpstrategy
,int dis
)
{
this.movestrategy
= movestrategy
;
this.jumpstrategy
= jumpstrategy
;
this.d
= dis
;
}
public void Move()
{
movestrategy
.Move(d
);
}
public void Jump()
{
jumpstrategy
.Jump();
}
}
public interface IMovestrategy
{
public void Move(int a
);
}
public class Moving_normal: IMovestrategy
{
public void Move(int a
)
{
Debug
.Log("๋ณธ์ธ์"+a
+"๋งํผ ์ด๋์ํฌ ๋ก์ง");
//์ฌ๊ธฐ์ ๋์ ๊ฐ์ฒด๋ฅผ ์์ง์ด๊ฒํ๋ ๋ก์ง์ ๋ฃ๊ณ ์ถ์
}
}
์์ง์ด๊ฒํ๊ณ ์ถ์ ๊ฐ์ฒด
public class Person_exe:MonoBehaviour
{
Person p
= new Person(new Moving_normal(),new Jump_normal(),3);
void Start()
{
p
.Move();
p
.Jump();
}
}์ฌ๊ธฐ๊น์ง ์ง๋ดค์ต๋๋ค. ์ด์ ย Person_exe๋ฅผ ๊ฐ๋ค๋ถํ ๊ฒ์์ค๋ธ์ ํธ์ย ์ ๋ณด๋ฅผ Person์ผ๋ก ๋๊ฒจ์ฃผ๊ณ ย Move์์ ํธ๋์คํผ์ด๋์ด๋ผ๋์ง, ๋ฌผ๋ฆฌ์ด๋์ด๋ผ๋์ง ๊ตฌํํ๊ณ ์ถ์๋ฐย ์๋ฌด๋ฆฌ ์งฑ๊ตฌ๋ฅผ ๊ตด๋ ค๋ ๊ฒ์์ค๋ธ์ ํธ์ย ์ ๋ณด๋ฅผ Person์ผ๋ก ๋๊ฒจ์ค ๋ฐฉ๋ฒ์ด ์๋ ์ค๋ฆ
๋๋ค.. ๊ตฌ์กฐ์ ์ผ๋ก ๋ถ๊ฐ๋ฅํ๊ฐ์? ๋ง์ฝ ๊ทธ๋ ๋ค๋ฉด ์ด๋ค ๋ฐฉ๋ฒ์ ์จ์ผํ๋์ง ์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค ใ
ใ
..
๋จ์ํ๊ฒ Person ์์ฑ์์ GameObject ๋ฃ์ด์ฃผ๊ณ Person ์์ฑํ ๋ ์ฃผ๋ฉด ๋๋๊ฑฐ์๋๊ฐ
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
public class Person_exe:MonoBehaviour { Person p = new Person(new Moving_normal(),new Jump_normal(),3,//....??);
Person_exe๋ถ๋ถ์ ์ด๋ป๊ฒํด์ผํ ์ง ๋ชจ๋ฅด๊ฒ ์ด์..ใ
์ฃ์กํด์ ์ด๊ฒ ๋๊ธ๋ก ๋ฌ๋ฉด ๊ธ์ด ์์๊ฒ ์๋์ค๋ค์..
public class Person{ private IMovestrategy movestrategy; private IJumpstrategy jumpstrategy; int d; GameObject obj; public Person(IMovestrategy movestrategy, IJumpstrategy jumpstrategy,int dis,GameObject getobj) { this.movestrategy = movestrategy; this.jumpstrategy = jumpstrategy; this.d = dis; this.obj = getobj; }
์ด์ฐจํผ ์ด๋/์ ํ ์ํค๋ ค๋ฉด ์ด๋ค๊ฐ์ฒด๊ฑด transform์ด๋ rigidbody๊ฐ ํ์ํ๋๊น person ๋งค๊ฐ๋ณ์๋ก ํ๋ ์ ์ธํ๋๊ฒ ๋์๋ฏ?
ํน์ ์์ธํ ์ค๋ช ํด์ฃผ์ค ์ ์๋์ ์ ๊ฐ ์ฝ๋ฆฐ์ด๋ผ ์์๋ฑํ๊ฒ ๋ชป์์๋ค์ด์์ ใ ใ
person ํด๋์ค ์์ Transform trans ์ ์ธ Person ์์ฑ์๋ก ๋ฐ์์ ๋ฃ๊ธฐ
์์ ์จ๋์ ๊ฑฐ๋ ๋๊ฐ์๊ฑฐ์ transform.translate๋ก ์ด๋ํด๋ ๋๊ณ rigitbody.moveposition์ผ๋ก ์ด๋ํด๋ ๋๊ณ ๋ญ ๋ณ์๋ก ์ฐ๋ ์ฐจ์ด์ง