using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Move : MonoBehaviour {


ย  ย  //movePower, jumpPower๋ฅผ 5๋กœ ์ง€์ •

ย  ย  public float movePower = 5f;

ย  ย  public float jumpPower = 5f;

ย  ย ย 

ย  ย  Rigidbody2D rigid;//?


ย  ย  Vector3 movement;

ย  ย  bool isJumping = false;//isJumping์„ false๋กœ ์ •์˜


ย  ย  void Start () {

ย  ย  ย  ย  rigid = gameObject.GetComponent<Rigidbody2D> ();//Rigidbody2D ํ˜ธ์ถœ, rigid๋กœ ์ •์˜

}

void Update () {

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

ย  ย  ย  ย  ย  ย  isJumping = true;

ย  ย  ย  ย  }//Jumpํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด isJunping์„ true๋กœ ์ „ํ™˜

}


ย  ย  void FixedUpdate()

ย  ย  {

ย  ย  ย  ย  Player_Move();

ย  ย  ย  ย  Player_Jump();

ย  ย  ย  ย  //ํ˜ธ์ถœ

ย  ย  }


ย  ย  void Player_Move() {

ย  ย  ย  ย  Vector3 moveVelocity = Vector3.zero;


ย  ย  ย  ย  if (Input.GetAxisRaw("Horizontal") < 0) {

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

ย  ย  ย  ย  }//์™ผ์ชฝ์œผ๋กœ ์ด๋™


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

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

ย  ย  ย  ย  }//์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™


ย  ย  ย  ย  transform.position += moveVelocity * movePower * Time.deltaTime;//์ด๋™ ๋ช…๋ น

ย  ย  }


ย  ย  void Player_Jump() {

ย  ย  ย  ย  if (!isJumping)

ย  ย  ย  ย  ย  ย  return;//์ ํ”„ ์•ˆํ•œ ์ƒํƒœ


ย  ย  ย  ย  rigid.velocity = Vector2.zero;//ํ”Œ๋ ˆ์ด์–ด์˜ ์ขŒํ‘œ ์ •์˜


ย  ย  ย  ย  Vector2 jumpvelocity = new Vector2(0, jumpPower); //์ ํ”„ ํ• ๋•Œ์˜ ์ขŒํ‘œ

ย  ย  ย  ย  rigid.AddForce(jumpvelocity, ForceMode2D.Impulse); //์ ํ”„ ๋ช…๋ น


ย  ย  ย  ย  isJumping = false; //์ดˆ๊ธฐํ™”

ย  ย  }

}


๊ฐ„๋‹จํ•˜๊ฒŒ ์ด๋™์ด๋ž‘ ์ ํ”„๋งŒ ํ•˜๋Š” ์ฝ”๋“œ์ž„