2D๊ฒŒ์ž„ ์ทจ๋ฏธ๋กœ ํ•œ๋ฒˆ ๋Œ€์ถฉ ๊ตฌ๊ธ€๋ง ํ•˜๋ฉด์„œ ๋งŒ๋“œ๋Š”๋ฐ


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class scr : MonoBehaviour

{


ย  ย  public float movePower = 1f;

ย  ย  public float jumpPower = 1f;


ย  ย  Rigidbody2D rigid;


ย  ย  Vector3 movement;

ย  ย  bool isJumping = false;

ย  ย  // Start is called before the first frame update


ย  ย  void Start()

ย  ย  {

ย  ย  ย  ย  rigid = gameObject.GetComponent ();

ย  ย  }


ย  ย  // Update is called once per frame


ย  ย  void Update()

ย  ย  {

ย  ย  ย  ย  if (Input.GetButtonDown("Jump"))

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  isJumping = true;

ย  ย  ย  ย  }

ย  ย  }



ย  ย  void FixedUpdate()

ย  ย  {

ย  ย  ย  ย  Move();

ย  ย  ย  ย  Jump();


ย  ย  }


ย  ย  void Move()


ย  ย  {

ย  ย  ย  ย  Vector3 moveVelocity = Vector3.zero;


ย  ย  ย  ย  if (Input.GetAxisRaw("Horizontal")

ย  ย  ย  ย  {


ย  ย  ย  ย  ย  ย  moveVelocity = Vector3.left;

ย  ย  ย  ย  }


ย  ย  ย  ย  else if (Input.GetAxisRaw("Horizontal") > 0)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  moveVelocity = Vector3.right;

ย  ย  ย  ย  }

ย  ย  ย  ย  transform.position += moveVelocity * movePower * Time.deltaTime;

ย  ย  }

ย  ย  void Jump()

ย  ย  {

ย  ย  ย  ย  if (!isJumping)

ย  ย  ย  ย  ย  ย  return;

ย  ย  ย  ย  rigid.velocity = Vector2.zero;


ย  ย  ย  ย  Vector2 jumpVelocity = new Vector2(0, jumpPower);

ย  ย  ย  ย  rigid.AddForce(jumpVelocity, ForceMode2D.Impulse);


ย  ย  ย  ย  isJumping = false;

ย  ย  }

}



์•„๋ฌด๋ฆฌ w๋‚˜ ์ŠคํŽ˜์ด์Šค๋ฐ”๋ฅผ ๋ˆŒ๋Ÿฌ๋„ ์ ํ”„๊ฐ€ ์•ˆ๋จ


์–ด๋””๊ฐ€ ์ž˜๋ชป๋œ๊ฑฐ์ž„?