728x90
반응형
플레이어 물리법칙 적용
플레이어 이름 변경
왼쪽 패널에 녹색 박스 생긴거 확인.
플레이어가 점프하게 만들기
- 스크립트
행동 스크립트를 생성해보기.
Player 라고 이름 지정
위와 같이 작성.
연결해주기.
점프 계속 가능 오류 고치기
&& 사용
따라 적기
플랫폼과 부딪힌 것.
using UnityEngine;
public class Player : MonoBehaviour
{
[Header("Settings")]
public float JumpForce;
[Header("References")]
public Rigidbody2D PlayerRigidBody;
private bool isGrounded = true;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded) {
PlayerRigidBody.AddForceY(JumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.name == "Platform") {
isGrounded = true;
}
}
}
728x90
반응형
'> Unity > 챌린지' 카테고리의 다른 글
김장 게임을 만들어보기 (9) - 애니메이션 2 (0) | 2025.01.23 |
---|---|
김장 게임을 만들어보기 (8) - 애니메이션 1 (0) | 2025.01.23 |
김장 게임을 만들어보기 (6) - 플레이어 점프 1 (0) | 2025.01.22 |
김장 게임을 만들어보기 (5) - 스크롤링 스크립트 3 (0) | 2025.01.22 |
김장 게임을 만들어보기 (4) - 스크롤링 스크립트 2 (0) | 2025.01.22 |