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) ์ค์ ํด์คฌ์.
๋ ์ด์ด๋ง์คํฌ์ ๊ฐ ๋ฃ์ด์ค?
๋ ์ด์ด๋ง์คํฌ์ ๊ฐ?
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
์บก์ณ ๋ฐ์ ๊ธ์์ ํ์. ์ ๋๋ก groundLayer์ layer๊ฐ ๋ฃ์ด์ค๊ฑฐ๊ฐ์๋ฐ
OverlapCapsule ์๋ชป์ผ์ ํ๋ฅ ์ด ๋๊ธดํ๋ค. ์ด๊ฒ๋ง ๋ด์ ๋ชจ๋ฅด๊ฒ ๋๋ฐ
์บก์์์ ์ํด๋ก ๋ฐ๊ฟจ๋๋ฐ๋ ๋ฌดํ์ ํ๊ฐ ๊ณ ์ณ์ง์ง์์
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
์งง๊ฒ ๋ธ๊นํ๋ฉด ์ ๋๋๋ฐ ์ฐํํ๋ฉด ๋ฌดํ์ ํ์;
์ง๊ธ ์ isGround๋ ์ด๊ธฐํ๋ฅผ ์ํด์ค์ ํ๋ฒ true๋ฉด ๊ณ์ true์ธ ์ํ ์๋๊ฐ์??
์ด๊ฑฐ ๊ฐ์๋ฐ