반응형
- 코드 작성
using UnityEngine;
public class ParkourController : MonoBehaviour
{
public float jumpForce = 10f;
public float moveSpeed = 5f;
private bool isGrounded = false;
private Rigidbody2D rb;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
// 바닥에 닿아 있는지 확인
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, 0.1f);
// 점프
if (isGrounded && Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
// 좌우 이동
float horizontalInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(horizontalInput * moveSpeed, rb.velocity.y);
}
}
반응형