์ค๋ ์ ํ๋ธ ๋ณด๋ฉด์ ์ฒ์์ผ๋ก ์ ๋ํฐ ์ค์ตํด๋ดค๋๋ฐ
์์์ capsule ์ ํํ ์์ง์ด๋๋ฐ
๋ด๊ฐ ๋ง๋ ๊ฒ์ ์ ๊ทธ๋ฌ๋ค?
๋งฅ๋ถ m1 ์ฌ์ฉํ๋๋ฐ ์ข ์ดํด๊ฐ ์ ๊ฐ
ํค๋ณด๋ GetKeyDown ํ๋ฉด capsule์ด ์์ง์ด๋ ์ฌ์ด ์ฝ๋์ผ
ํ ๋ฒ GetKeyDown ํ๋ฉด 0.06 ์ฉ ์์ง์ด๊ณ
ํ ๋ฒ ๋ GetKeyDown ํ๋ฉด 0.02 ์ฉ ์์ง์ด๋ค
Time.deltaTime ๊ณฑํด์ ์์ง์ด๋ ๊ฒ๋ ๋ง๋ ๊ฒ ๊ฐ์๋ฐ..
์ ๋ํฐ ๋ฒ์ ๋ง๋ค ๋ค๋ฅธ ๊ฑฐ์ผ? ์๋๋ฉด ๋ด๊ฐ ๋ชจ๋ฅด๋ ๋ญ๊ฐ๊ฐ ์๋ ๊ฑฐ์ผ?
์ฝ๋๋ ์ด๋ฏธ์ง ์ฒจ๋ถํ์
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainController : MonoBehaviour
{
private float _fSpeed = 10.0f;
public GameObject capsParent;
public GameObject capsChild;
private bool _bHave = false;
// Start is called before the first frame update
void Start()
{
capsParent = GameObject.Find("CapsuleParent");
capsChild = GameObject.Find("CapsuleChild");
_bHave = false;
}
// Update is called once per frame
void Update()
{
if (capsParent != null)
{
float fMove = _fSpeed * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("Up Key Pressed");
capsParent.GetComponent<Transform>().Translate(new Vector3(0, 0, fMove));
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Debug.Log("Left Key Pressed");
capsParent.GetComponent<Transform>().Translate(new Vector3(fMove * -1.0f, 0, 0));
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
capsParent.GetComponent<Transform>().Translate(new Vector3(0, 0, fMove * -1.0f));
}
if(Input.GetKeyDown(KeyCode.RightArrow))
{
capsParent.GetComponent<Transform>().Translate(new Vector3(fMove, 0, 0));
}
if (Input.GetKeyDown(KeyCode.Space))
{
if(_bHave)
{
capsChild.transform.parent = null;
_bHave = false;
}
else
{
capsChild.transform.parent = capsParent.transform;
_bHave = true;
}
}
}
else
{
Debug.Log("Not Object");
}
}
}
Update์์ Getcomponent๋ฅผ ์จ์ ๊ทธ๋ฐ๊ฑฐ ์๋๊น
start๋ awake์์ ํ๋ฒ๋ง ํ๋ฉด ๋๋๋ฐ
์์์๋ณด์ฌ์ฃผ์
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
๊ธ ์์ฑํ ์ฌ๋์ธ๋ฐ ์ปคํผ์์์ ์์ ํ๋ค๊ฐ ์ด๋ํด์ ๋ชจ๋ฐ์ผ๋ก ๋๊ธ๋ด ์ ํ๋ธ ์์์๋ GetKey ๋ก ๋์ด์์ด์ ์ฝ๋ ์์ ํ๋๊น ์๋จ ๊ตฟ๊ตฟ ๋จ๋ฐ์ฑ ๋์์ GetKeyDown ์ฐ๋ ค๋ฉด ๋ณด์ ์ ์ด๋ป๊ฒ ํด์ค์ผ๋ผ? ์คํ์ ๊ฐ์ ๊ฒ ์๋๊ฑฐ์ผ?
์ฝ๋ ๋ณต์ฌํด์ ์ฑGPT์ ๋ถ์ฌ๋ฃ์ด๋ด
deltaTime์ ์ปดํจํฐ ์ฑ๋ฅ๋ฐ๋ผ ์๊ฐ๊ฐ ๋ฌ๋ผ์ ธ์ ๊ทธ๋ด๊ฑฐ์ ํ๋ ์ ์๊ฐ ๊ฐ์ ธ์์ ์ฐ๋๊ฑฐ๋ผ ๋ชจ๋ ํ๋ ์์ด ์ผ์ ํ์ง ์์๋ ์ด๋ค๊ฑธ ๊ตฌํํ๊ณ ์ถ์ด์ ์ ๋ ๊ฒ ์ฝ๋ ์ง ๊ฑฐ์ผ?