Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
[Unity] 2D 점프 본문
Unity 2D 점프
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour {
Rigidbody2D rgdy;
public float JP = 10f;
bool isJumping = false;
// Use this for initialization
void Start () {
rgdy = gameObject.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Space))
isJumping = true;
}
private void FixedUpdate()
{
Jumping();
}
void Jumping()
{
if (!isJumping)
return;
rgdy.velocity = Vector2.zero;
Vector2 jumpVelocity = new Vector2(0, JP);
rgdy.AddForce(jumpVelocity, ForceMode2D.Impulse);
isJumping = false;
}
}
'랭귀지 > Unity' 카테고리의 다른 글
| 유니티 이미지 플립 (오브젝트 이미지 뒤집기) (0) | 2018.04.07 |
|---|---|
| Unity GetButton, GetButtonDown, GetButtonUp 설명 및 사용법 (0) | 2018.04.06 |
| 유니티 점프시 카메라이동 (0) | 2018.04.02 |
| [Unity]애니메이터에 등록된 애니메이션 목록 가져오기 (0) | 2018.04.01 |
| [Unity3D] Script Editor 바꾸기 (0) | 2018.03.30 |
Comments