2D๊ฒ์ ์ทจ๋ฏธ๋ก ํ๋ฒ ๋์ถฉ ๊ตฌ๊ธ๋ง ํ๋ฉด์ ๋ง๋๋๋ฐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class scr : MonoBehaviour
{
ย ย public float movePower = 1f;
ย ย public float jumpPower = 1f;
ย ย Rigidbody2D rigid;
ย ย Vector3 movement;
ย ย bool isJumping = false;
ย ย // Start is called before the first frame update
ย ย void Start()
ย ย {
ย ย ย ย rigid = gameObject.GetComponent ();
ย ย }
ย ย // Update is called once per frame
ย ย void Update()
ย ย {
ย ย ย ย if (Input.GetButtonDown("Jump"))
ย ย ย ย {
ย ย ย ย ย ย isJumping = true;
ย ย ย ย }
ย ย }
ย ย void FixedUpdate()
ย ย {
ย ย ย ย Move();
ย ย ย ย Jump();
ย ย }
ย ย void Move()
ย ย {
ย ย ย ย Vector3 moveVelocity = Vector3.zero;
ย ย ย ย if (Input.GetAxisRaw("Horizontal")
ย ย ย ย {
ย ย ย ย ย ย moveVelocity = Vector3.left;
ย ย ย ย }
ย ย ย ย else if (Input.GetAxisRaw("Horizontal") > 0)
ย ย ย ย {
ย ย ย ย ย ย moveVelocity = Vector3.right;
ย ย ย ย }
ย ย ย ย transform.position += moveVelocity * movePower * Time.deltaTime;
ย ย }
ย ย void Jump()
ย ย {
ย ย ย ย if (!isJumping)
ย ย ย ย ย ย return;
ย ย ย ย rigid.velocity = Vector2.zero;
ย ย ย ย Vector2 jumpVelocity = new Vector2(0, jumpPower);
ย ย ย ย rigid.AddForce(jumpVelocity, ForceMode2D.Impulse);
ย ย ย ย isJumping = false;
ย ย }
}
์๋ฌด๋ฆฌ w๋ ์คํ์ด์ค๋ฐ๋ฅผ ๋๋ฌ๋ ์ ํ๊ฐ ์๋จ
์ด๋๊ฐ ์๋ชป๋๊ฑฐ์?
Debug.Log()๋ก ์ด๋๊ฐ ๋ฌธ์ ์ธ์ง ์์๋ด์
์ค ์ด๋ฐ๊ฒ ์๊ตฌ๋ ใณใณ