using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Player_Move : MonoBehaviour {


Rigidbody2D rigid;

private float Horizontal;

float Speed = 3.0f;

float Jpower = 3.0f;

public LayerMask groundLayer;

public Transform groundTrans;

bool isGround;

// Start is called before the first frame update

void Start()

{

rigid = GetComponent<Rigidbody2D>();

}


// Update is called once per frame

void Update()

{

isGround = Physics2D.OverlapCapsule(groundTrans.position, new Vector2(1.0f, 0.15f), CapsuleDirection2D.Horizontal, 0, groundLayer);


if (isGround == true && Input.GetKeyDown(KeyCode.Space))

{

rigid.velocity = Vector2.up * Jpower;

}


}


private void FixedUpdate()

{

Horizontal = Input.GetAxisRaw("Horizontal");


rigid.velocity = new Vector2(Horizontal * Speed, rigid.velocity.y);


}

}


๋ฌดํ•œ์ ํ”„ ์•ˆ๋˜๊ฒŒ ์˜ค๋ฒ„๋žฉ์œผ๋กœ ๋ฐ”๋‹ฅ์— ๋‹ฟ์•„์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๋‹ฟ์•„์žˆ์„๋•Œ๋งŒ ์ ํ”„ํ•˜๊ฒŒ๋” ํ–ˆ๋Š”๋ฐ

์ŠคํŽ˜์ด์Šค๋ฐ” ์—ฐํƒ€ํ•˜๋ฉด ์ญ‰์ญ‰ ์˜ฌ๋ผ๊ฐ€๋„ค


๋ญ˜ ์ž˜๋ชปํ•œ๊ฑฐ์ง€


ํ”Œ๋žซํผ์ด๋ž‘ ํ”Œ๋ ˆ์ด์–ด๋ธ” ์บ๋ฆญํ„ฐ์—๋Š” ํ™•์‹คํ•˜๊ฒŒ layer(ground) ์„ค์ •ํ•ด์คฌ์Œ.