using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody playerRigidbody;
public float speed = 8f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.UpArrow) == true)
{
playerRigidbody.AddForce(0f, 0f, speed);
}
if (Input.GetKey(KeyCode.DownArrow) == true)
{
playerRigidbody.AddForce(0f, 0f, -speed);
}
if (Input.GetKey(KeyCode.RightArrow) == true)
{
playerRigidbody.AddForce(speed, 0f, 0f);
}
if (Input.GetKey(KeyCode.LeftArrow) == true)
{
playerRigidbody.AddForce(-speed, 0f,0f );
}
public void Die()
{
gameObject.SetActive(false);
}
}
}
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
๋งค๊ฐ๋ณ์๋์ ์๊ด์๋๋ฐ;;?
AddForce ๋งค๊ฐ๋ณ์๋ ๋ง๊ฒ ๋ฃ์๋๋ฐ ์ ๋ ๋ญ ์๋ฆฌ๋
์ธ๊ฐค ์์ค ์ง์งใ ใ ใ ใ ใ ใ ใ ใ
์ด์ฒด์ ๋๊ตญ์ด๋ค true๋ ๋์ฒด ์ ๋ถ์ธ๊ฑฐ์ GetKeyDown์ ์ฐ๋๊ฐ ๊ทธ๋ฆฌ๊ณ Die ํจ์๋ ์ ๋ฐ์ดํธ ์์ ์ ์์
์ ๊ทธ๋ฌ๋ค ์ ๋ฐ์ดํธ ์์ ๋ฃ์ด์ ๊ทธ๋ฐ๊ฑฐ์์
๊ณ ๋ง์
true๋ ในใ ์ด๋ป๊ฒ ๋์จ๊ฑฐ๋?ใ ใ ใ ใ getkey ์์ฒด๊ฐ ๋ฒํผ ๋๋ ์๋๋ง true ๋๋๊ฑด๋ฐ
๋ชจ๋ฅด๊ฒ ์ ์ง๊ธ ๋ฐฐ์ฐ๋ ๋จ๊ณ๋ผ์ ์ฑ ์๋์จ๋๋ก ํ๊ณ ์๋์ค์ธ๋ฐ ์คํ๋๊ธดํด
์กด๋ ์๋ ์ฑ ์ธ๊ฐ ๊ทธ๋ด์์ผ๋ก ์ง๋๊ณ ํ์๋จน๋คใ ใ true๊ฐ์๊ฑฐ ์๋ถ์ฌ๋ ๋จ
ํจ์๋ฅผ ํจ์์์์ ์ ์ธํ๋ ธ update๋ die - dc App
GetKey๋ GetKeyDown์ด๋ ๋ฆฌํดํ์ ์ bool์ด๋ผ ์คํ์ผ์ ๋ฐ๋ผ true ๋ถ์ผ์๋ ์๊ณ ์๋ถ์ผ์๋ ์๋๋ฐ true๋ ์ด๋์์๋ ํ๋๊ฒ ์๊ธฐ๋ ธ
์ธ๋ถ์ด๋ค์ ๊ทธ๋ฐ ๊ฑฐ ๋ชฐ๋ผ์