์›€์ง์ด๋Š”๊ฒŒ ์ค‘์š”ํ•œ๊ฑฐ๊ฐ™์•„์„œ ์›€์ง์ด๋Š”๊ฒƒ๋งŒ ์งฐ์Œ.



public class Test : MonoBehaviour {

ย  ย  public float maxSpeed = 7f;

ย  ย  private int check = 0;

ย  ย  Rigidbody2D rb;

ย  ย ย 

// Use this for initialization

void Start () {

ย  ย  ย  ย  rb = GetComponent<Rigidbody2D>();

}


ย  ย  // Update is called once per frame

ย  ย  void FixedUpdate()

ย  ย  {


ย  ย  ย  ย  if (check == 1)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  rb.velocity = new Vector2(-1 * maxSpeed, rb.velocity.y);

ย  ย  ย  ย  }

ย  ย  ย  ย  else if (check == 2)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  rb.velocity = new Vector2(0, rb.velocity.y);

ย  ย  ย  ย  }

ย  ย  ย  ย  else if (check == 3)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  rb.velocity = new Vector2(1 * maxSpeed, rb.velocity.y);

ย  ย  ย  ย  }

ย  ย  ย  ย  else if (check == 4)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  rb.velocity = new Vector2(0, rb.velocity.y);

ย  ย  ย  ย  }

ย  ย  }


ย  ย  public void leftDown()

ย  ย  {

ย  ย  ย  ย  check = 1;

ย  ย  }

ย  ย  public void leftUp()

ย  ย  {

ย  ย  ย  ย  check = 2;

ย  ย  }

ย  ย  public void rightDown()

ย  ย  {

ย  ย  ย  ย  check = 3;

ย  ย  }

ย  ย  public void rightUp()

ย  ย  {

ย  ย  ย  ย  check = 4;

ย  ย  }


}




viewimage.php?id=2abcdd23dad63db0&no=29bcc427b38b77a16fb3dab004c86b6f113d37b1bcb66f76596c07cc6c418d68c23af2750db4e9302bf213f616e7b013c03056ce2f2ab56fc98a


์Šค์ƒท์€ ์™ผ์ชฝ๋งŒ ์žˆ๋Š”๋ฐ ์ด๋Ÿฐ์‹์œผ๋กœ ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ์ถ”๊ฐ€ํ•ด์ค˜์„œ ๋ˆŒ๋ฅด๊ณ ์žˆ์œผ๋ฉด Downํ•จ์ˆ˜๊ฐ€ ๋–„๋ฉด Upํ•จ์ˆ˜๊ฐ€ ๊ทธ๋ž˜์„œ ๊ทธ ๋ฒ„ํŠผ์— ๋งž์€ ์ฒดํฌ๊ฐ’ if๋กœ ์ธ์‹ํ•ด์„œ velocity๋กœ ์›€์ง์˜€์Œ.