MapleStory Finger Point

๐Ÿ”ต C,C++,C#/Unity

์œ ๋‹ˆํ‹ฐ/VR ์ •๋ฆฌ #1

HYEJU01 2024. 4. 8. 00:48

VR์ด๋ž€

  • ๊ฐ€์ƒํ˜„์‹ค์€ ์‹ค์ œ๊ฐ€ ์•„๋‹ˆ์ง€๋งŒ ์‹ค์ œ์™€ ๊ฐ™์ด ์ธ๊ณต์œผ๋กœ ๋งŒ๋“  ํ˜„์‹ค
  • ์‹ค์ œ๋Š” ์•„๋‹ˆ์ง€๋งŒ ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹ค์ œ์™€ ๊ฐ™์€ ๊ฒฝํ—˜์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ธฐ์ˆ ์˜ ๋ฐœ์ „์— ๋”ฐ๋ผ ์ ์  ๋” ์‚ฌ์‹ค์ ์ธ ๊ฒฝํ—˜์„ ์ถ”๊ตฌ

VR์˜ ํŠน์ง•

  • ์ž์œจ์„ฑ
  • ์ƒํ˜ธ์ž‘์šฉ์„ฑ
  • ํ˜„์กด๊ฐ

VR์˜ ํ•ต์‹ฌ

  • ๊ฐ€์ƒ์„ธ๊ณ„
  • ์ƒํ˜ธ์ž‘์šฉ
  • ๋ชฐ์ž…๊ฐ

VR์˜ ์ž…์ฒด ํšจ๊ณผ

  • ๊ณต๊ฐ„๊ฐ๊ฐ (์™ผ์ชฝ์˜ค๋ฅธ์ชฝ ์‹œ์•ผ ๋‹ค๋ฅด๋‹ค)
  • ์›๊ทผ๊ฐ
  • ๊ฑฐ๋ฆฌ๊ฐ

AR์ •์˜

  • ์‹ค์ œ์™€ ๊ฐ€์ƒ์˜ ๊ฒฐํ•ฉ
  • ์‹ค์‹œ๊ฐ„ ์ƒํ˜ธ์ž‘์šฉ
  • \*3D๋กœ ํ‘œ์‹œ)

AR ์ด๋ž€

  • ์ฆ๊ฐ•ํ˜„์‹ค์ด๋ž€ ํ™•์žฅ๋œ ํ˜„์‹ค๋กœ 100% ๋ฏธ๋ฆฌ ์ œ์ž‘๋œ ํ™˜๊ฒฝ์—์„œ ํ”Œ๋ ˆ์ดํ•˜๋Š” ๊ฐ€์ƒํ˜„์‹ค ์ฝ˜ํ…์ธ ์™€ ๋‹ฌ๋ฆฌ,

๋ˆˆ์•ž์— ์žˆ๋Š” ํ˜„์‹ค์„ธ๊ณ„ ์œ„์— ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ฝ˜ํ…์ธ  ์ œ์ž‘์ž๊ฐ€ ๋งŒ๋“  ๊ฐ€์ƒ์š”์†Œ๋ฅผ ๊ฒฐํ•จํ•˜์—ฌ ๋ณด๋‹ค ํ˜„์‹ค๊ฐ ๋„˜์น˜๋Š” ์ฝ˜ํ…์ธ 

Meterial

albedo : ์•Œ๋ฒ ๋„ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ํ‘œ๋ฉด์˜ ๊ธฐ๋ณธ ์ƒ‰์ƒ์„ ์ œ์–ดํ•œ๋‹ค

nomarl map : ์‹ค์ œ ๊ธฐํ•˜ํ•™์œผ๋กœ ํ‘œํ˜„๋˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋น›์„ ํฌ์ฐฉํ•˜๋Š” ๋ฒ”ํ”„ ๋งต์œผ๋กœ ์ฃผ๋ฆ„ ๋ฐ ์Šคํฌ๋ž˜์น˜์™€ ๊ฐ™์€ ํ‘œ๋ฉด ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ๋ชจ๋ธ์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋Š” ํŠน๋ณ„ํ•œ ์ข…๋ฅ˜์˜ ํ…์Šค์ณ

motallic : ๊ธˆ์† ์›Œํฌํ”Œ๋กœ(๋ฐ˜์‚ฌ ์›Œํฌํ”Œ๋กœ์™€ ๋ฐ˜๋Œ€)์—์„œ ์ง์—…ํ•  ๋•Œ ํ‘œ๋ฉด์˜ ๋ฐ˜์‚ฌ๋„ ๋ฐ ๋น›์‘๋‹ต์€ ๊ธˆ์† ์ˆ˜์ค€ ๋ฐ Smoothness ์ˆ˜์ค€์— ์˜ํ•ด ์ˆ˜์ •๋œ๋‹ค

roughness : ๊ฑฐ์งˆ๊ธฐ ์ •๋„๋กœ ๋งค๋„๋Ÿฌ์šฐ๋ฉด ๊ฑฐ์šธ์ฒ˜๋Ÿผ ๋ฐ˜์‚ฌํ•˜์ง€๋งŒ, ๊ฑฐ์งˆ์ •๋„๊ฐ€ ๋†’์•„์ง€๋ฉด ๋ฐ˜์‚ฌ๋ฅผ ใ„ฑ์˜ ํ•˜์ง€ ์•Š๋Š”๋‹ค

height : 0~1 ์‚ฌ์ด ํ‘๋ฐฑ ๊ฐ’๋“ค์„ ์ด์šฉํ•ด mesh์˜ ๋†’๋‚ฎ์ด๊ฐ€ ์žˆ์–ด ๋ณด์ด๊ฒŒ ํ‘œํ˜„ํ•œ๋‹ค. ์†๋„ ์ œ์ผ ๋น ๋ฆ„

 

์ž์œ ๋„ Dof

๋…๋ฆฝ์ ์œผ๋กœ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ VR HMD ๋Š” 3DoF 6DoF

HMD

  • NST(Non-See-Through) Display - ํ˜„์‹ค์˜ ์™ธ๋ถ€์ •๋ณด๊ฐ€ ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค
  • OST(Optical See-Through) Display - ํ˜„์‹ค์˜ ์ •๋ณด์™€ ๊ฐ™์ด ๊ฐ€์ƒ์„ธ๊ณ„ ์ •๋ณด๋„ ๋ณด์—ฌ์ค€๋‹ค

3DoF > ํšŒ์ „๋งŒ ๋œ๋‹ค.

  • ๊ต์ • ์ž์„ธ์—์„œ ๋จธ๋ฆฌ ํšŒ์ „๋งŒ ์ธ์‹ํ•œ๋‹ค ⇒ ๋กœํ…Œ์ด์…˜ ํŠธ๋ž˜ํ‚น(Rotation Tracking)
  • ๊ณ ๊ฐœ๋ฅผ ๋„๋•๊ฑฐ๋ฆฌ๋Š” ํšŒ์ „ : X-axis ์ค‘์‹ฌ์œผ๋กœ ํ”ผ์น˜(pitch)
  • ๊ณ ๊ฐœ๋ฅผ ์ขŒ์šฐ๋กœ ํšŒ์ „ : Y-axis ์ค‘์‹ฌ์œผ๋กœ ์š”(yaw)
  • ๊ณ ๊ฐœ๋ฅผ ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊บพ์–ด์ฃผ๋Š” ํšŒ์ „ : Z-axis ์ค‘์‹ฌ์œผ๋กœ ์š”(yaw)

6DoF > ์ขŒํ‘œ + ํšŒ์ „ ๋ชจ๋‘ ๊ฐ€๋Šฅ

  • ์•ž๊ณผ ๋’ค, ์˜†์œผ๋กœ๋„ ์ด๋™์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์ธ์‹ํ•˜๋ฏ€๋กœ ํฌ์ง€์…”๋„ ํŠธ๋ž˜ํ‚น(Positional Tracking
  • ์ขŒ์šฐ ์ด๋™ : X-axis ์ค‘์‹ฌ์œผ๋กœ ์Šค์›จ์ด(sway)
  • ์œ„์•„๋ž˜ ์ด๋™ : Y-axis ์ค‘์‹ฌ์œผ๋กœ ํžˆ๋ธŒ(heave)
  • ์•ž๋’ค ์ด๋™ : Z-axis ์ค‘์‹ฌ์œผ๋กœ ์…œ์ง€(surge)

1์ดˆ๋งˆ๋‹ค ์ž‘๋™ํ•˜๋Š” ๋ฐฉ๋ฒ•

float count = 0;

count += Time.deltaTime;
//ํ•œ๋งˆ๋””๋กœ ํ•œ ํ”„๋ ˆ์ž„์„ ์ง„ํ–‰ํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฐ ์‹œ๊ฐ„
  • ์ ์šฉ) 5์ดˆํ›„์— “์ž‘๋™”์ด๋ผ๋Š” ์ฝ˜์†”์ฐฝ์— ์กฐ๊ฑด๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ ๋‚˜์˜ค๋„๋ก ํ•ด ๋ณด์„ธ์š”.
**if((int)count > 5)
        {
            count = 0f;
            print("์ž‘๋™");
        }
        else
        {
            count += Time.deltaTime;
           // print(count);
           // print((int)count);
        }**

๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ (๋งˆ์šฐ์Šค ํด๋ฆญ)

if (Input.GetMouseButtonDown(0))
{
	print("๋งˆ์šฐ์Šค๋‹ค์šด");
}
if (Input.GetMouseButtonUp(0))
{
	print("๋งˆ์šฐ์Šค์—…");
}
//‘0’๋Š” ๋งˆ์šฐ์Šค๋ฒ„ํŠผ ์ค‘์— ์™ผ์ชฝ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €๋Š”์ง€๋ฅผ ์ฐพ๋Š”๊ฒƒ์œผ๋กœ 
//== true ๊ฐ€ ์ƒ๋žต๋˜์–ด ์žˆ๋‹ค
  • ์ ์šฉ) ํด๋ฆญํ•˜๋ฉด ๋ฉˆ์ถ”์–ด ์žˆ๋Š” ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ๋ฅผ ํšŒ์ „์‹œ์ผœ ๋ณธ๋‹ค. speed ๋ณ€์ˆ˜๊ฐ€ 0์ด์—ˆ๋‹ค๊ฐ€ ๋งˆ์šฐ์Šค๋ฅผ ํด๋ฆญํ•˜๋ฉด speed์˜ ๊ฐ’์„ ์ถ”๊ฐ€์‹œ์ผœ ์ค€๋‹ค. ๊ฐ์†ํ•˜๋Š” ์›๋ฆฌ๋Š” 1๋ณด๋‹ค ์ž‘์€ ์‹ค์ˆ˜๋ฅผ ๊ณฑํ•ด์ค€๋‹ค. speed *= 0.98f;

๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ (๋งˆ์šฐ์Šค ์œ„์น˜ ๊ฐ’)

์›๋ž˜ ์œ„์น˜ = Input.mousePosition.x;
๋งˆ์šฐ์Šค๋ฅผ ๋–ผ์—ˆ์„ ๋•Œ์˜ ์œ„์น˜ = Input.mousePosition.x;
  • ๋จผ์ € ํ™”๋ฉด์— ํ•„์š”ํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋‚˜์—ด์‹œํ‚ค๊ณ  ๋‚œ ํ›„์— ๊ฐ ์˜ค๋ธŒ์ ํŠธ์— ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ์ปจํŠธ๋กค๋Ÿฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.
    • ์”ฌ์„ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด ๊ตฌ์„ฑํ•˜๋ฉด ํ•ญ์ƒ ์ €์žฅํ•˜๋Š” ์Šต๊ด€์„ ๊ฐ€์ง€๋„๋ก ํ•˜์ž. ๋งˆ์šฐ์Šค๋ฅผ ํด๋ฆญํ•œ ํ›„์— ๊ณต๊ธฐ์ด ์˜๋Š” ๋“ฏ ๋’ค๋กœ ์ด๋™ํ•œ ์ขŒํ‘œ๊ฐ’์„ ๊ณ„์‚ฐํ•˜์—ฌ ์ฐจ์˜ ์†๋„๋ฅผ ๋ณ€ํ™”์‹œํ‚จ๋‹ค. ์›๋ž˜ ์œ„์น˜์™€ ๋งˆ์šฐ์Šค๋ฅผ ๋–ผ์—ˆ์„ ๋•Œ์˜ ๊ฐ’์„ ๊ฐ๊ฐ ๋ฐ›๋Š”๋‹ค.

๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ

  • ํฌํ•จ๋œ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ฐพ๋Š” ๋ฐฉ๋ฒ•
    • UI์˜ Text๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  Text๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•
    ~~ํ™”๋ฉด์— UI > Text๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. ์ด๋ฆ„์„ ‘distance’์œผ๋กœ ํ•œ๋‹ค.
    GameObejct dis;
    dis = GameObjct.Find(“distance”);
    dis.GetComponent<Text>().text = “Game Stat!”;
    
    ๊นƒ๋ฐœ๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฐจ์ด๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
    GameObject flag;
    float length;
    flag = GameObjct.Find(“flag”);
    length =flag.transform.position.x - this.transform.position.x ;
    dis.GetComponent<Text>().text =length.ToString(”F2”) “m”;~~
    
    • ์˜ค๋””์˜ค ํ”Œ๋ ˆ์ด ์‹œํ‚ค๊ธฐ
    • ~~AudioSurce ์ปดํฌ๋„ŒํŠธ๋Š” CD ํ”Œ๋ ˆ์ด์–ด์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 
      ์Œ์›์ด ๋˜๋Š” ์Œ์•… ํŒŒ์ผ์„ ์„ค์ •ํ•ด ๋‘๋ฉด ์Œ์„ ๋‚ด๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
      ์ปดํฌ๋„ŒํŠธ๋ฅผ Audio - Audio Source ๋ฃฐ ์ถ”๊ฐ€ํ•œ๋‹ค. 
      ์ฒ˜์Œ๋ถ€ํ„ฐ ํ”Œ๋ ˆ์ด ๋˜์ง€ ์•Š๋„๋กœ๊ณ  Play On Awake ์ฒดํฌ๋ฅผ ํ’€์–ด์ค€๋‹ค.
      GetComponent<AudioSource>().Play();~~
      

 

//carController.cs
float speed;
float startPos;
float endPos;

void Update()
{
	if (Input.GetMouseButtonDown(0)) //๋งˆ์šฐ์Šค๋‹ค์šด
	{
		this.startPos = Input.mousePosition.x;
		// this.speed = 2f * Time.deltaTime;
	}

	if (Input.GetMouseButtonUp(0))//๋งˆ์šฐ์Šค์—…
	{
		this.endPos = Input.mousePosition.x;
		float sLength = (endPos - this.startPos)/500;
		print(sLength);

	if (sLength > 0) {
		this.speed = sLength;
		GetComponent<AudioSource>().Play();
	}

}
	this.transform.Translate(speed, 0f, 0f); //์ด๋™
	this.speed *= 0.98f;
}
//gameController.cs
using UnityEngine.UI;
GameObject car;
GameObject textUI;
GameObject flag;

void Start()
{
	this.car = GameObject.Find("Car");
	this.textUI = GameObject.Find("distance");
	this.flag = GameObject.Find("Flag");
}

	void Update()
	{
		float length = (this.car.transform.position.x - this.flag.transform.position.x).magnitude;
		// magitude .๋ฒกํ„ฐ ๊ณ„์‚ฐ?	
		print(length);

	if (length > 0)
	{
		this.textUI.GetComponent<Text>().text = length.ToString("F2") + "m";
	}
}

https://ssabi.tistory.com/23


  • ๋ฉ”์‹œ์ง€์™€ ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ…
**MonoBehaviour**๋Š” ๋ฌด์—‡์ธ๊ฐ€?
์œ ๋‹ˆํ‹ฐ์˜ ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๋Š” MonoBehaviour ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•œ๋‹ค. 

MonoBehaviour ํด๋ž˜์Šค๋Š” ์œ ๋‹ˆํ‹ฐ์—์„œ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ์ œ๊ณตํ•˜๋Š” ํด๋ž˜์Šค์ด๋ฉฐ ์ปดํฌ๋„ŒํŠธ์— ํ•„์š”ํ•œ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.
์ฆ‰ MonoBehaviour ๋ฅผ ์ƒ์†ํ•ด์„œ ๋งŒ๋“  ์ปดํฌ๋„ŒํŠธ๋Š” ์œ ๋‹ˆํ‹ฐ์˜ ์ œ์–ด๋ฅผ ๋ฐ›๊ฒŒ ๋œ๋‹ค.
์ปดํฌ๋„ŒํŠธ ํŒจํ„ด์—์„œ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ์„œ๋กœ ๊ด€์‹ฌ์ด ์—†๋‹ค. 

๋”ฐ๋ผ์„œ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์— ์ถ”๊ฐ€๋œ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ‘์ผ๋ถ€๋Ÿฌ ์ฐพ์•„๋‚ด๊ธฐ’ ์ „์—๋Š” ์•Œ ์ˆ˜ ์—†๋‹ค. ์œ ๋‹ˆํ‹ฐ์—์„œ๋Š” ์–ด๋–ค ๊ธฐ๋Šฅ์„ ์‹คํ–‰์‹œํ‚ค๊ณ  ์‹ถ์„ ๋•Œ
‘๋‹น์‚ฌ์ž๋ฅผ ์ง์ ‘ ์ฐพ์•„๊ฐ€๋Š”’๋ฐฉ๋ฒ•๋ณด๋‹ค๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ๋‚ ๋ฆฌ๋Š” ๋ฐฉ์‹๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
์ฆ‰, ๋ฐœ๋™ ์‹œํ‚ค๊ณ  ์‹ถ์€ ๊ธฐ๋Šฅ์˜ ์ด๋ฆ„์„ ๋‹ด์•„ ๊ฒŒ์ž„ ์›Œ๋“œ์— ๋ฉ”์‹œ์ง€๋ฅผ ๋ฟŒ๋ฆฌ๋ฉด, ๊ฒŒ์ž„ ์›Œ๋“œ์˜ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋ชจ๋‘ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›๊ณ , 
๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์€ ์˜ค๋ธŒ์ ํŠธ๊ฐ€ ๋ฉ”์‹œ์ง€์—์„œ ๋ช…์‹œ๋œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. 

์ด๋•Œ ๋ฉ”์‹œ์ง€๋Š” ๋ˆ„๊ฐ€ ๋ณด๋‚ธ์ง€๋ฅผ ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š๊ธฐ๋•Œ๋ฌธ์— ์ปดํฌ๋„ŒํŠธ๋Š” ๋…๋ฆฝ์„ฑ์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค. 
์ด๋Ÿฐ์‹์˜ **๋ฌด์ฐจ๋ณ„์  ๋ฉ”์‹œ์ง€ ์ „๋‹ฌ ๋ฐฉ์‹์„‘๋ธŒ๋กœ๋“œ์บ์ŠคํŒ…’์ด๋ผ๊ณ  ํ•œ๋‹ค.**
**์ด ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ…์€ ์•ž์œผ๋กœ ์‚ฌ์šฉํ•  ‘์œ ๋‹ˆํ‹ฐ ์ด๋ฒคํŠธ ๋ฉ”์„œ๋“œ’๊ฐ€ ๋™์ž‘ํ•˜๋Š” ์›๋ฆฌ์ด๋‹ค**
  • using
์œ ๋‹ˆํ‹ฐ์—์„œ ์ƒˆ๋กœ์šด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด 
์Šคํฌ๋ฆฝํŠธ ์ƒ๋‹จ์— using ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋กœ ํ•ด๋‹น ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค์— ๋“ค์–ด์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ํ˜„์žฌ ์Šคํฌ๋ฆฝํŠธ์— ๋ถˆ๋Ÿฌ์˜จ๋‹ค.

Debug.Log(“Hello World!”);
์˜ Debug๋Š” UnityEngine ์‚ฌ์šฉํ•œ ๊ฒƒ์ด๋‹ค.
  • ๋ฉ”์„œ๋“œ (์–ธ์ œ)๋ณ„ 5๊ฐœ
**Awake()
-์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ์‹œ ํ•œ ๋ฒˆ๋งŒ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜๋กœ Start ํ•จ์ˆ˜ ํ˜ธ์ถœ ์ „ ํ˜ธ์ถœ๋œ๋‹ค.
๋‹ค๋ฅธ ์Šคํฌ๋ฆฝํŠธ ์ž‘๋™ํ•˜๊ธฐ ์ „์— ํ˜ธ์ถœํ•œ ๊ฒƒ์ด ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉ, ๋น„ํ™œ์„ฑํ™”๊ฐ€ ๋˜์–ด๋„ ํ™œ์„ฑํ™”๊ฐ€ ๋œ๋‹ค.

Start() [๊ธฐ๋ณธ ํ•จ์ˆ˜] -> ์•„๋‘์ด๋…ธ setup ๋Š๋‚Œ์˜ ํ•จ์ˆ˜
- Update ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ ์ „์— ํ•œ ๋ฒˆ๋งŒ ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜

Update() [๊ธฐ๋ณธ ํ•จ์ˆ˜] -> ์•„๋‘์ด๋…ธ loop ๋Š๋‚Œ์˜ ํ•จ์ˆ˜
- 1ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๊ณ„์† ์‹คํ–‰ํ•œ๋‹ค. ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์ด ์ผ์ •ํ•˜์ง€ ์•Š๋‹ค. ์ปดํ“จํ„ฐ ์‚ฌ์–‘์ด๋‚˜ ๊ทธ๋•Œ์˜ ์ฒ˜๋ฆฌ ์†๋„์— ๋”ฐ๋ผ ๋ณ€ํ™”ํ•œ๋‹ค.

LateUpdate() 
- ๋ชจ๋“  Updateํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ ๋œ ํ›„์— ํ˜ธ์ถœ๋œ๋‹ค. ํŠน์ • ์˜ค๋ธŒ์ ํŠธ ๊ฒฐ๊ณผ๋กœ ๋ณด์—ฌ์ค„ ๋•Œ(์นด๋ฉ”๋ผ ๋”ฐ๋ผ๊ฐˆ๋•Œ)

FixedUpdate() 
- ๋ฌผ๋ฆฌ์—”์ง„์˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ๊ณ„์‚ฐ ์ฃผ๊ธฐ๋กœ ๊ธฐ๋ณธ๊ฐ’์€ 0.02์ดˆ (30fps)๋งˆ๋‹ค ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜๋กœ 1์ดˆ์— 50ํ”„๋ ˆ์ž„์œผ๋กœ ๊ฑฐ์˜ ์ •ํ•ด์ ธ ์žˆ๋‹ค

OnEnable() 
- ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ๋˜๋Š” ์Šคํฌ๋ฆฝํŠธ ํ™œ์„ฑํ™” ์‹œ ํ˜ธ์ถœ(์ ๊ตฐ์ด ์ฃฝ์„ ๋•Œ)

OnDisable() 
- ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ๋˜๋Š” ์Šคํฌ๋ฆฝํŠธ ๋น„ ํ™œ์„ฑํ™” ์‹œ ํ˜ธ์ถœ(์ ๊ตฐ์ด ์ฃฝ์€ ํ›„์˜ ์ปจํŠธ๋กค)**
**using System;
void Awake()
{
	print("๋ฉ”์„œ๋“œ ์ค‘ ๊ฐ€์žฅ ๋จผ์ € ํ˜ธ์ถœ" + DateTime.Now.ToString());
}

void Start()
{
	print("๋ฉ”์„œ๋“œ ์ค‘ ์ธ์‹ํ•˜์—ฌ ์ž‘๋™์„ ์‹œ์ž‘ํ•  ๋•Œ ํ•œ๋ฒˆ ํ˜ธ์ถœ" + DateTime.Now.ToString());
}

void Update()
{
	print("๋งค ํ”„๋ ˆ์ž„ ํ˜ธ์ถœ" + DateTime.Now.ToString());
}

void FixedUpdate()
{
	print("๊ณ ์ • ํ”„๋ ˆ์ž„ ํ‘œ์ค€ ํ˜ธ์ถœ(Rigidbody ์ปดํฌ๋„ŒํŠธ์ผ ๋•Œ ์ถ”์ฒœ)" + DateTime.Now.ToString());
}

1) 'Edit -> Project Settings -> Time'์„ ์„ ํƒ ํ›„ 'InsPector'์—์„œ 'Fixed Timestep'๊ฐ’์„ '0.01666667'๋กœ ํ•˜๋ฉด 60ํ”„๋ ˆ์ž„์œผ๋กœ ๊ณ ์ •.(30ํ”„๋ ˆ์ž„์€
'0.03333333'๋กœ ํ•˜๋ฉด๋จ.) 0.02๋Š” 50ํ”„๋ ˆ์ž„
๋‹จ 'void Update ()'๋Œ€์‹  'void FixedUpdate ()'๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.

2) 'void Start ()'๋˜๋Š” 'void Awake ()' ๊ฐ™์ด ์‹œ์ž‘์‹œ ํ•œ๋ฒˆ ์ž‘๋™ํ•˜๋Š” ํ•จ์ˆ˜์—์„œ 'Time.captureFramerate = 60;'๋ฅผ ์ ์œผ๋ฉด ๋””์Šคํ”Œ๋ ˆ์ด๋˜๋Š”
ํ”„๋ ˆ์ž„์ด ๊ฐ•์ œ๋กœ 60ํ”„๋ ˆ์ž„์œผ๋กœ ๋ณ€๊ฒฝ.(30์„ ์ ์œผ๋ฉด 30ํ”„๋ ˆ์ž„์ด ๋จ.)**
  • ๊ณต๊ฐ„์ด๋™

3D ๊ณต๊ฐ„์— ๋ฐฐ์น˜ํ•˜๋Š” 3D ์˜ค๋ธŒ์ ํŠธ๋Š” ์œ„์น˜๋ฅผ ํ‘œํ˜„ํ•œ ๊ฐ’, ์ฆ‰ ์ขŒํ‘œ๋ฅผ ๊ฐ€์ง„๋‹ค. ์ขŒํ‘œ๋ฅผ ์ธก์ •ํ•  ๊ธฐ์ค€์ด ๋  ์›์ ์˜ ์œ„์น˜ x,y,z์ถ• ๋ฐฉํ–ฅ์„ ์„ค์ •ํ•˜์—ฌ ๋ฌผ์ฒด๊ฐ€ ์–ด๋””์— ๋ฐฐ์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ‘œํ˜„ํ•˜๋Š” ๊ธฐ์ค€๊ณผ ์ฒด๊ณ„๋ฅผ ์ขŒํ‘œ๊ณ„(coordinate system)๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ์ขŒํ‘œ๊ณ„๋Š” ๊ณต๊ฐ„์—์„œ ‘์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ’ ์–ผ๋งˆ๋งŒํผ ์ด๋™ํ•œ ๊ฑฐ๋ฆฌ์— ๋ฐฐ์น˜ํ•  ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ๊ธฐ์ค€์ด๋‹ค. ์ฆ‰ ์”ฌ ์ฐฝ์— ํ‘œํ˜„๋˜๋Š” ํ‰ํ–‰ ์ด๋™ ํ‹€์˜ ํ™”์‚ดํ‘œ๊ฐ€ ์ขŒํ‘œ๊ณ„๋ฅผ ํ‘œํ˜„ํ•œ ๊ฒƒ์ด๋‹ค.

  • ๋ฒกํ„ฐ

์˜ค๋ธŒ์ ํŠธ์˜ ์œ„์น˜๋‚˜ ๋ฐฉํ–ฅ ์ขŒํ‘œ๋Š” ๊ฐ ์ถ•๋งˆ๋‹ค์˜ ๋‹ค๋ฅธ ๊ฐ’์„ ํ•˜๋‚˜์˜ ๋ฉ์–ด๋ฆฌ๋กœ ๋ฌถ์–ด ๋†“์€ ๋ณ€์ˆ˜๋กœ ์ฝ๊ณ  ์“ด๋‹ค. ์ด๋Ÿฐ ๋ณ€์ˆ˜์˜ ์ž๋ฃŒํ˜•์ด ๋ฒกํ„ฐ์ด๋‹ค. ์œ ๋‹ˆํ‹ฐ ์ƒ์—์„œ ์œ„์น˜, ํšŒ์ „, ํฌ๊ธฐ๋ฅผ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•ด์„œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด๋‹ค. Vector3 (3D) : float 3๊ฐ€์ง€์˜ x, y, z ์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด๋‹ค. Vector2 (2D) : float 2๊ฐ€์ง€์˜ x, y์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…๋‹ˆ๋‹ค. ๋ฒกํ„ฐ ๋ณ€์ˆ˜๋Š” ‘๋ฐฉํ–ฅ’๊ณผ ‘ํฌ๊ธฐ’๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฉํ–ฅ๊ณผ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ•  ๋•Œ ๋ง์…ˆ, ๋บ„์…ˆ, ์Šค์นผ๋ผ ๊ณฑ ๋“ฑ์— ์˜ํ•ด ์กฐ์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค

**Vector3 tmp = new Vector3(10, 10, 10); ๋˜๋Š” Vector3 tmp;
void Start()
{
	tmp = new Vector3(10, 10, 10);
	transform.position = tmp;
}**
  • ๋ฒกํ„ฐ ์—ฐ์‚ฐ๋ฒ•
  • ๋ฒกํ„ฐ + ๋ฒกํ„ฐ

๋ฒกํ„ฐ์™€ ๋ฒกํ„ฐ๋ฅผ ๋”ํ•˜๋ฉด ๋ฒกํ„ฐ๋Š” ํž˜์ด๊ธฐ์— ๋‘ ํž˜์ด ๋™์‹œ์— ์ž‘์šฉํ•œ ๊ฒฐ๊ณผ๋กœ ๋‚˜ํƒ€๋‚œ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฒกํ„ฐ๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ์ง€์ ์—์„œ ๋ถ€ํ„ฐ ๋‘ ๋ฒˆ์งธ ๋ฒกํ„ฐ๋ฅผ ์—ฐ๊ฒฐํ•ด์„œ ๋‘ ๋ฒกํ„ฐ๋ฅผ ์—ฐ๊ฒฐํ•œ ๊ฒฐ๊ณผ ๋„๋‹ฌํ•˜๋Š” ์œ„์น˜๋ฅผ ์‹œ์ž‘์ ์—์„œ ์„ ์œผ๋กœ ์—ฐ๊ฒฐํ•œ ๋ชจ์Šต์ด ๋˜๋Š” ๊ฒƒ์ด ๋‹ค. ๋ฒกํ„ฐA ๋Š” (1,0)์ด๊ณ  ๋ฒกํ„ฐB๋Š” (0,1)์ผ ๋•Œ ํ•ฉ์€ ((1+0), (0+1)) = (1,1)

  • ๋ฒกํ„ฐ - ๋ฒกํ„ฐ

๋ฒกํ„ฐ B+ ๋ฒกํ„ฐ(-A) ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. -A๋ฒกํ„ฐ๋Š” ์›๋ž˜์˜ A ๋ฒกํ„ฐ๋ฅผ ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ ๋’ค์ง‘๋Š” ํ˜•ํƒœ์ด๋‹ค. ๋ฒกํ„ฐA ๋Š” (1,0)์ด๊ณ  ๋ฒกํ„ฐB๋Š” (0,1)์ผ ๋•Œ ๋ฒกํ„ฐB ๋นผ๊ธฐ ๋ฒกํ„ฐA์ด๋ฏ€๋กœ ((0-1), (1-0)) = (-1,1) ์ด๋•Œ ๋ฒกํ„ฐB ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐฉํ–ฅ์ด ๊ทธ๋ ค์ง€๊ธฐ์— ๋ฒกํ„ฐ์˜ ๋บ„์…ˆ์€ ๋‚˜์˜ ์œ„์น˜์—์„œ ์ƒ๋Œ€๋ฐฉ์„ ๋ฐ”๋ผ๋ณด๋Š” ๋ฐฉํ–ฅ์„ ๊ตฌํ•  ๋•Œ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค


  • ์ ˆ๋Œ€์œ„์น˜, ์ƒ๋Œ€์œ„์น˜

๋ฒกํ„ฐ๋Š” ๋ฐฉํ–ฅ๊ณผ ๊ธธ์ด(ํฌ๊ธฐ)์„ ๊ฐ€์ง„๋‹ค. ์ด๊ฒƒ์€ ํ™”์‚ดํ‘œ์˜ ๋ฐฉํ–ฅ๊ณผ ๊ธธ์ด๋กœ ๋น„์œ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ (1,1)์ด๋ผ๋ฉด ๋‘ ๊ฐ€์ง€ ์˜๋ฏธ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.

  • ์ƒ๋Œ€ ์ขŒํ‘œ : (๋‚ด๊ฐ€ ์–ด๋””์žˆ๋Š”์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ) ํ˜„์žฌ ์ขŒํ‘œ์—์„œ (1, 1)๋งŒํผ ๋” ๊ฐ€๋ ค๊ณ  ํ•œ๋‹ค.
  • ์ ˆ๋Œ€ ์ขŒํ‘œ : ๊ฒŒ์ธ ์„ธ์ƒ ์†์—์„œ ๋‚˜์˜ ์ขŒํ‘œ๊ฐ€ (1, 1)์ด๋‹ค.

์ƒ๋Œ€ ์ขŒํ‘œ๋Š” ๋ฒกํ„ฐ์˜ ๊ฐ’์€ ์˜ค์ง ํ™”์‚ดํ‘œ์˜ ๋ฐฉํ–ฅ๊ณผ ํ™”์‚ดํ‘œ์˜ ๊ธธ์ด๋งŒ ํ‘œํ˜„ํ•œ ๊ฒƒ์ด๋‹ค. ๋‹จ, ํ™”์‚ดํ‘œ์˜ ์‹œ์ž‘์ ์ด ์›์ (0,0)์ด๋ผ๋Š” ํŠน์ˆ˜ํ•œ ์ „์ œ๋ฅผ ๊ฐ€์ •ํ•˜๋ฉด ๋‘ ๋ฒˆ์งธ ์˜๋ฏธ๋กœ ํ•ด์„ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰ ๋ฒกํ„ฐ๋Š” ์ ˆ๋Œ€์ ์ธ ์ขŒํ‘œ์™€ ์ƒ๋Œ€์ ์ธ ๋ฐฉํ–ฅ๊ณผ ํฌ๊ธฐ(๊ธธ์ด)๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

Vector2 a = new Vector2(x, y);
Vector3 b = new Vector3(x, y, z);
Vector4 c = new Vector4(x, y, z, w);
Vector2 ๋Š” 2์ฐจ์›์œผ๋กœ ์ขŒ์šฐ ์ถ•๊ณผ ์ƒํ•˜ ์ถ•์˜ ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค๋Š” ๋œป์ด๋‹ค.
Vector3 ๋Š” 3์ฐจ์›์œผ๋กœ ์•ž์˜ ๋‘ ์ถ•์— ์ „ํ›„ ์ถ•์ด ์ถ”๊ฐ€ ๋œ ๊ฒƒ์ด๋‹ค.
  • ์ ˆ๋Œ€ ์ขŒํ‘œ ์ด๋™
**โ‘  transform.position
	transform.position = new Vector3(0.0f, 0.0f, 0.0f); //์œ„์น˜
์ ˆ๋Œ€์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. 

โ‘ก transform.rotation
	transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); //๊ฐ๋„
์ ˆ๋Œ€์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํšŒ์ „์‹œํ‚ด

โ‘ข transform.localScale
	transform.localScale = new Vector3(0.0f, 0.0f, 0.0f) // ํฌ๊ธฐ**

  • ๋ฒกํ„ฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์œ„์น˜ ๋ณ€๊ฒฝ
Vector3 tmp;
Vector3 plusPos = new Vector3(2,2,2);
Vector3 minusPos = new Vector3(3, 3, 3);
Vector3 newPos;
void Start()
{
	tmp = new Vector3(2, 0, 2);
	transform.position = tmp;
	//newPos = tmp + plusPos;
	newPos = minusPos - tmp;
	transform.position = newPos;
}
  • ์ƒ๋Œ€์  ์ขŒํ‘œ๋กœ ์ด๋™
**โ‘  transform.Translate()
	this.transform.Translate(new Vector3(0.0f, 0.0f, 0.0f));
	this.transform.Translate(0.0f, 0.0f, 0.0f);
์ƒ๋Œ€์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์œ„์น˜์‹œํ‚ด(๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๊ฐ’๋งŒํผ ์ด๋™)

โ‘ก transform.Rotate()
	transform.Rotate(0.0f, 0.0f, 0.0f);
์ƒ๋Œ€์ขŒํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํšŒ์ „์‹œํ‚ด(๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๊ฐ’๋งŒ ํผ ํšŒ์ „)**

  • ๋ฒกํ„ฐ * ์Šค์นผ๋ผ, ๋ฒกํ„ฐ / ์Šค์นผ๋ผ

๋ฒกํ„ฐ์˜ ๋ชธํ†ต ๊ธธ์ด๋Š” ํž˜์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๋ฐฉํ–ฅ์˜ ๋ณ€ํ™” ์—†์ด ํž˜์˜ ํฌ๊ธฐ๋งŒ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜ ์ค„์ผ ๋•Œ ๋ฒกํ„ฐ์— ํž˜์˜ ๋ณ€ํ™”๋Ÿ‰ ๋งŒํผ

‘์Šค์นผ๋ผ ๊ฐ’’์„ ๊ณฑํ•˜๊ฑฐ๋‚˜ ๋‚˜๋ˆ„๋ฉด ๋œ๋‹ค. ๋ฒกํ„ฐ์— ์Šค์นผ๋ผ ๊ณฑํ•˜๋ฉด (-3,4) * 2 = (-32, 42) = (-6, 8)

๋ฒกํ„ฐ์˜ ๋ชธํ†ต ๊ธธ์ด๋Š” ํž˜์˜ ํฌ๊ธฐ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. 
๋ฐฉํ–ฅ์˜ ๋ณ€ํ™”์—†์ด ํž˜์˜ ํฌ๊ธฐ๋งŒ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜ ์ค„์ผ ๋•Œ 
๋ฒกํ„ฐ์— ํž˜์˜ ๋ณ€ํ™”๋Ÿ‰๋งŒํผ ‘์Šค์นผ๋ผ ๊ฐ’’์„ ๊ณฑํ•˜๊ฑฐ๋‚˜ ๋‚˜๋ˆ„๋ฉด ๋œ๋‹ค.
๋ฒกํ„ฐ์— ์Šค์นผ๋ผ ๊ณฑ์„ ํ•˜๋ฉด
(-3,4) * 2 = (-3*2, 4*2) = (-6, 8)
  • ์Šค์นผ๋ผ๋กœ ์œ„์น˜ ์ด๋™
float speed = 0.02f;
Vector3 varPose = new Vector3(1,0,0);

void Update()
{
	transform.Translate(speed, 0, 0); //speed(0.02f) ์†๋„๋กœ x์ขŒํ‘œ๋งŒ! ์ด๋™ํ•œ๋‹ค.
//transform.Translate(varPose * speed); ์ด๋™์„ ํ•œ๋‹ค.
}
// ์ผ์ •ํ•œ ์‹œ๊ฐ„์œผ๋กœ ์ด๋™

float speed = 2f; // ์†๋„
Vector3 varPose = new Vector3(1,0,0); //๋ฐฉํ–ฅ
void Update()
{
	transform.Translate(varPose * speed * Time.deltaTime);
}


  • ๋ฒกํ„ฐ์˜ ํฌ๊ธฐ(๊ธธ์ด)

2D ๋ฒกํ„ฐ (-3, 4)์ด ์žˆ๋‹ค. (-3, 4)์˜ ๋ฐฉํ–ฅ์€ ์  (-3, 4)๋กœ ํ–ฅํ•˜๋Š” ํ™”์‚ดํ‘œ์˜ ๋ฐฉํ–ฅ์ด๋‹ค. (-3, 4)์˜ ํฌ๊ธฐ๋Š” ํ™”์‚ดํ‘œ์˜ ๊ธธ์ด์— ํ•ด ๋‹นํ•œ๋‹ค. ํ™”์‚ดํ‘œ ๊ธธ์ด๋Š” ํ™”์‚ดํ‘œ๋ฅผ ๋น—๋ณ€์œผ๋กœ ํ•˜๋Š” ์ง๊ฐ์‚ผ๊ฐํ˜•์„ ๊ทธ๋ฆฐ ๋’ค ํ”ผํƒ€๊ณ ๋ผ์Šค์˜ ์ •๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. (-3, 4)์˜ ํฌ๊ธฐ๋Š” ๋ฃจํŠธ (-3)์ œ๊ณฑ + 4์ œ๊ณฑ = 5 Vector3.magnitude; Vector3 a = new Vector3(3, 3, 3); float b = a.magnitude; // ๋Œ€๋žต 5.19...๊ฐ€ ๋œ๋‹ค. ๊ฒŒ์ž„์—์„œ๋Š” ํ”Œ๋ ˆ์ด์–ด๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ ๊ณผ์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์•Œ์•„๋‚ด๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ๋ฒกํ„ฐB์—์„œ ๋ฒกํ„ฐA์˜ ๊ฐ’์„ ๋นผ์ฃผ์–ด ๋˜ ํ•˜๋‚˜์˜ ๋ฒกํ„ฐ๊ฐ’์„ ๊ตฌํ•ด์ค€๋‹ค. (5,4) - (-4, -3) = (9, 7) ์ด๊ฒƒ์„ ํ”ผํƒ€๊ณ ๋ผ์Šค ์ •๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์—ฌ 9์˜ ์ œ๊ณฑ + 7์˜ ์ œ๊ณฑ = ๊ธธ์ด๊ฐ’์˜ ์ œ๊ณฑ์ด๋ฏ€๋กœ

81 + 49 = 130๋ฃจํŠธ 130์„ ํ•˜๋ฉด 11,40175425099138 ์ด๊ฒƒ์€ c= B-A, c.magnitude ๋ผ๊ณ  ๊ฐ„๋‹จํžˆ ๊ฒฐ๊ณผ๊ฐ’์„ ์•Œ๋ ค์ค€๋‹ค.

์ƒˆ C#Script ๋กœ ๋งŒ๋“ค๊ณ  ์ด๋ฆ„์€ ‘magTest’

float speed = 2f;
// ๋‚ด์ž์‹ ์ด ์•„๋‹Œ ์›€์ง์ด๋Š” ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ์‚ฌ์šฉ
Vector3 varPose = new Vector3(1,0,0);
Vector3 myPose;
Vector3 parePose;
float magFloat;

void Start(){
	myPose = transform.position;
}

void Update()
{
	transform.Translate(varPose * speed * Time.deltaTime);
	parePose = transform.position - myPose;
	magFloat = parePose.magnitude;
	Debug.Log(magFloat); = //print(magFloat);

	if(magFloat > 10){
		// ๋ ˆ์ด๋”๋ง์—์„œ ๋ฒ—์–ด๋‚ฌ์Šต๋‹ˆ๋‹ค.
	}
}
//this ๊ฐ€ ์ƒ๋žต, gameObject

 

  • ๋ฐฉํ–ฅ ๋ฒกํ„ฐ = ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)

๋ฐฉํ–ฅ ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•œ๋‹ค.

ํฌ๊ธฐ๊ฐ€ 1์ด๋ฏ€๋กœ ๋ฐฉํ–ฅ์€ ๊ฐ™์ง€๋งŒ, ํฌ๊ธฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฒกํ„ฐ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ธฐ์ค€์œผ๋กœ ์‚ผ์„ ์ˆ˜ ์žˆ๋‹ค. (1, -1)์˜ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋ฅผ ๊ตฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋ฒกํ„ฐ์˜ ์‹œ์ž‘์ ์—์„œ ๋ฐ˜์ง€๋ฆ„์ด 1์ธ ์›์„ ๊ทธ๋ ค์„œ(1, -1)์˜ ์› ๋ฐ”๊นฅ ๋ถ€๋ถ„์„ ์ž˜๋ผ๋‚ธ๋‹ค. (๋ฐฉํ–ฅ์€ ์œ ์ง€ํ•˜๋ฉด์„œ) ๋ฒกํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๋ฒกํ„ฐ ์ •๊ทœํ™”์ด๋‹ค.

์™œ ๊ธธ์ด๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ผ๊นŒ? ๋ฐฉํ–ฅ์˜ ๊ฐ’์ด ์†๋„์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์น˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์ด๋ผ๋Š” ํ‘œํ˜„์œผ๋กœ๋Š” ์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ ์–ผ๋งˆ๋งŒํผ์˜ ์†๋ ฅ์„๊ฐ€์ง€๋Š”์ง€ ๋– ์˜ฌ๋ฆฌ๊ธฐ ํž˜๋“ค๋‹ค. ์ด๋•Œ (3, -3)์„ ์ˆœ์ˆ˜ํ•œ ๋ฐฉํ–ฅ๊ณผ ์ˆœ์ˆ˜ํ•œ ์†๋ ฅ์„ ๋‚˜๋ˆ„์–ด ํ‘œํ˜„ํ•˜๋ฉด ๋ฐฉํ–ฅ๊ณผ ์†๋„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. (3, -3) = ๋ฐฉํ–ฅ * ์†๋ ฅ ๋˜๋Š” ์ด๋™๊ฑฐ๋ฆฌ ๋ฒกํ„ฐ์˜ ์Šค์นผ๋ผ ๊ณฑ์„ ๋ฐฐ์› ๊ณ  ๋•Œ๋ฌธ์— (3, -3)๋Š” (1, -1)์˜ 3๋ฐฐ์— ํ•ด๋‹น๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋ ๊ฒƒ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์†๋ ฅ ์ž์ฒด๋ฅผ ํ‘œํ˜„ํ•˜์ง€ ๋ชปํ•œ๋‹ค. ์†๋ ฅ์ด 3์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. (1, -1)์˜ ํฌ๊ธฐ(magnitude)๋Š” 1.414… ์ด๊ธฐ๋•Œ๋ฌธ์ด๋‹ค. ‘A์˜ ๋ฐฉํ–ฅ์œผ๋กœ B๋งŒํผ์˜ ์†๋ ฅ’์„ ‘๋ฒกํ„ฐA * ์Šค์นผ๋ผB’๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฒกํ„ฐA๋Š” 1์ด ๋˜์ง€ ์•Š์œผ๋ฉด ์‹ค์ œ ์†๋ ฅ์€ B๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค.

๋”ฐ๋ผ์„œ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ฆ‰ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ๋‹ค. ๊ฒŒ์ž„์—์„œ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ ์˜ ์œ„์น˜๋ฅผ ํŒŒ์•…ํ•˜๊ณ  ์œ„์น˜์˜ ๋ฒกํ„ฐ ๊ฐ’(๋ฒกํ„ฐ C)์„ ์•Œ๊ณ  ์žˆ์„ ๋•Œ ๊ทธ์— ๋งž๋Š” ๊ฐ’์œผ๋กœ ๊ณ„์† ์•ž์œผ๋กœ ๋‚˜์•„๊ฐ„๋‹ค๋ฉด,

๋ฒกํ„ฐC์˜ ๊ฐ’์— ๋”ฐ๋ผ ์–ด๋Š ๋•Œ๋Š” ๋นจ๋ผ์ง€๊ธฐ๋„ ๋˜๋Š” ๋Š๋ ค์ง€๊ธฐ๋„ ํ•œ๋‹ค. ์ด๋Ÿฐ ์ƒํ™ฉ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ฒกํ„ฐ์˜ ๊ธธ์ด๋ฅผ 1๋กœ ์ •๊ทœํ™”ํ•œ๋‹ค.

  • normailzed ์ ์šฉํ›„ ๋น„๊ต
float speed = 2f;
Vector3 varPose = new Vector3(1,1,1);
//์ด์ „์œ„์น˜
Vector3 prePose;
Vector3 parePose;
float magFloat;

void Update()
{
	prePose = transform.position;
	**transform.Translate(varPose.normalized * speed * Time.deltaTime);** 
	parePose = transform.position - prePose;
	magFloat = parePose.magnitude;
	Debug.Log(magFloat);
}
  • ํ˜„์žฌ ์œ„์น˜์—์„œ ๋ชฉ์ ์ง€๋กœ ํ–ฅํ•˜๋Š” ๋ฐฉํ–ฅ
public GameObject pos1;
public GameObject pos2;
Vector3 objectPos1;
Vector3 objectPos2;
float speed = 10;
Vector3 direction;
float magTarget;
Vector3 nowSpeed;

void Update()
{
	objectPos1 = pos1.transform.position;
	objectPos2 = transform.position;
	magTarget = (objectPos1 - objectPos2).magnitude;
	direction = (objectPos1 - objectPos2).normalized;

	if (magTarget < 10 )
	{
		nowSpeed = direction * speed * Time.deltaTime;
	}
	else
	{
		nowSpeed = new Vector3(0,0,0);
	}

	transform.Translate(nowSpeed);
}

 

 

 

 


  • ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•
**(1) Input.GetKey**
GetKey, GetKeyDown, GetKeyUp

if(Input.GetKey(“Name”))
{ //๋ช…๋ น}
right, left, up, down, space, tab, delete, a, b, c, 1, 2, 3… ๋“ฑ

**(2) Name๋ถ€๋ถ„์— KeyCode**

if(Input.GetKey(KeyCode.UpArrow))
{ //๋ช…๋ น }
Input.GetKeyDown(“space”) == Input.GetKeyDown(KeyCode.Space)
  • ๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ
**(2) Input.GetButton**
GetButton, GetButtonDown, GetButtonUp
if(Input.**GetButtonDown**(“ButtonName”))
{ //๋ช…๋ น }
ButtonName์„ ๋ˆ„๋ฅด๋Š” ๋™์•ˆ true๋กœ ๋ฌด๊ธฐ๋ฅ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฒ„ํŠผ ํŠธ๋ฆฌ๊ฑฐ๋กœ ์‚ฌ์šฉํ• ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
Edit > Project Setting > Input์—์„œ ๋ฏธ๋ฆฌ ์„ค์ •๋œ ButtonName์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ‘Fire1’๋Š” ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ

**(2) Input.GetMouseButton**
GetMouseButton, GetMouseButtonDown, GetMouseButtonUp
if (Input.**GetMouseButtonDown**(0))
{
	print("๋งˆ์šฐ์Šค๋‹ค์šด");
}

**GetMouseButtonDown(0) : ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(1) : ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(2) : ๋งˆ์šฐ์Šค ์ค‘์•™(ํœ ) ๋ฒ„ํŠผ**
  • Rigidbody
Player ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์›€์ง์ž„์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•ด Rigidbody๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
Add Component > Physics > Rigidbody

- ์ค‘๋ ฅ Use Gravity ๋ฅผ ์ฒดํฌํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ฐ‘์œผ๋กœ ๋–จ์–ด์ง„๋‹ค. 
Mass๊ฐ’์— ๋”ฐ๋ผ ๋–จ์–ด์ง€๋Š” ์ค‘๋Ÿ‰ ํ‘œํ˜„ํ•œ๋‹ค. 

-์บก์Š์ฒ˜๋Ÿผ ๋ฐ”๋‹ฅ๋ฉด์ด ๊ณก์„ ์ผ ๊ฒฝ์šฐ ์ค‘๋ ฅ์œผ๋กœ ์˜ํ–ฅ์œผ๋กœ ์“ฐ๋Ÿฌ์งˆ ์ˆ˜ ์žˆ๋‹ค. 
Constaints์—์„œ ์œ„๋กœ ํŠ•๊ฒจ๋‚˜๊ฐ€์ง€ ์•Š๋„๋ก Freeze Position์˜ Y ์ฒดํฌํ•œ๋‹ค.
์ถฉ๋Œ ์ดํ›„ ์›ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐ”๋ผ๋ณด๋„๋ก Freeze Rotation์˜ X์™€ Z๋ฅผ ์ฒดํฌํ•œ๋‹ค.

- ์ถฉ๋Œ์ฒดํฌ๋Š” Collider ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋Š” ๋ชจ๋‘ ์ถฉ๋Œ ์ฒดํฌ๋ฅผ ํ•œ๋‹ค. 
๋‹จ, Is Kinematic์ด ์ฒดํฌ๊ฐ€ ๋˜๋ฉด ๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๊ฒŒ ๋œ๋‹ค.

ํ†ตํ†ตํŠ€๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ(๋ฌผ๋ฆฌ ์žฌ์งˆ ๋งŒ๋“ค์–ด์„œ ์ ์šฉํ•˜๊ธฐ)
- Freeze Position์˜ Y ์ฒดํฌ ํ’€๊ธฐ
- Project์ฐฝ์˜ Create > Physic Material ์ถ”๊ฐ€, Bounciness ๊ฐ’์„ 1
- Player์˜ Collider์˜ Material์— ์ถ”๊ฐ€ํ•œ๋‹ค.
  • Rigidbody์— ํž˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™
[Rigidbody.AddForce]
public void AddForce(float x, float y, float z, forceMode);
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ํž˜์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํž˜์˜ ๋ฐฉํ–ฅ์„ ๋”ฐ๋ผ ์ผ์ •ํ•œ ํž˜์„ ์ง€์†์ ์œผ๋กœ ๋ถ€์—ฌํ•œ๋‹ค. 
forceMode๋ฅผ ์ง€์ •ํ•˜๋ฉด ๊ฐ€์†(Acceleration), ์ถฉ๊ฒฉ(Impulse), ์†๋„๋ณ€๊ฒฝ(Velocity Change)๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
์—…๋ฐ์ดํŠธ ๋ฌธ์—์„œ ๋ฐฉํ–ฅํ‚ค๋กœ ํž˜์ด ๊ฐ€ํ•ด์ง€๋„๋ก ์ž‘์„ฑํ•˜๊ฒŒ ๋œ๋‹ค
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐธ์กฐ๋ณ€์ˆ˜๋กœ ์กฐ์ ˆํ•˜๊ธฐ
์ฐธ์กฐ ํƒ€์ž…์œผ๋กœ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ ์กฐ์ข… ๊ฐ€๋Šฅํ•˜๋‹ค. .์ฐธ์กฐ ๋ณ€์ˆ˜๋Š” ์‹ค์ฒด๋Š” ์•„๋‹ˆ์ง€๋งŒ, ์‹ค์ฒด์ฒ˜๋Ÿผ
์ฐธ์กฐ๊ฐ’์„ ์ €์žฅํ•œ๋‹ค. ์ด๋กœ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์Šคํฌ๋ฆฝํŠธ์—์„œ ์ฐธ์กฐ ํƒ€์ž… ๋ณ€์ˆ˜๋กœ ์„ ์–ธ, ์ ‘๊ทผํ•˜์—ฌ, ์ œ์–ด
๊ฐ€๋Šฅํ•˜๋‹ค.
public Rigidbody playerRigidbody;
๋กœ ์„ ์–ธํ•œ ํ›„์—
playerRigidbody.AddForce(0, 500, 0);

<aside> ๐Ÿ’€ ๋ฌธ์ œ

-Rigidbody ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ง์ ‘ ํ• ๋‹นํ•˜์ง€ ์•Š์€ ๋ฐฉ๋ฒ•์€?

: AddFoce()๋Š” ์ ์ง„์ ์œผ๋กœ ์†๋„๊ฐ€ ์ฆ๊ฐ€๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋นจ๋ผ์ง€๋Š”๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค.

: ์ž…๋ ฅ ๊ฐ์ง€ ์ฝ”๋“œ๊ฐ€ ๋ณต์žกํ•˜๋‹ค. ์ฆ‰, IF ๋ฌธ์„ ๋„ˆ๋ฌด ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

</aside>

  • ๋งˆ์šฐ์Šค์™€ ์กฐ์ด์Šคํ‹ฑ
(1) Axis(์ถ•์„ ์ด์šฉ)
Input.GetAxis(“Horizontal”) 
Input.GetAxis(“Vertical”)
Axis์€ ์›€์ง์ด์ง€ ์•Š์„ ๋•Œ๋Š” 0, ์ˆ˜ํ‰์—์„œ ์™ผ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด -1, ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด 1 ์ด๋ผ๋Š” ๊ฐ’
์ˆ˜์ง์—์„œ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€๋ฉด 1, ๋‚ด๋ ค๊ฐ€๋ฉด -1 ์ด๋ผ๋Š” ๊ฐ’
“Horizontal”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์™ผ์ชฝ ๋ฐฉํ–ฅํ‚ค, A | ์–‘์˜ ๋ฐฉํ–ฅ : ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅํ‚ค, D 
“Vertical”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์•„๋ž˜์ชฝ ๋ฐฉํ–ฅํ‚ค, S | ์–‘์˜ ๋ฐฉํ–ฅ : ์œ„์ชฝ ๋ฐฉํ–ฅํ‚ค, W 

(2) ๋งˆ์šฐ์Šค ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ์ด๋™ ํ™•์ธ
Input.GetAxis(“Mouse X”)
Input.GetAxis(“Mouse Y”)
  • Rigidbody์˜ ์ด๋™์„ ์ผ์ •ํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ
์ฒ˜์Œ ์›€์ง์ผ ๋•Œ๋Š” ์ž˜ ์›€์ง์ด์ง€๋งŒ, ์ฒœ์ฒœํžˆ ๊ฐ€๋‹ค๊ฐ€ ๋’ค๋กœ ๊ฐˆ์ˆ˜๋ก ๋นจ๋ผ์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์›€์ง์ด๋‹ค ๋ฐฉํ–ฅ ์ „ํ™˜์„
ํ•ด๋ณด๋ฉด ๋ฐ”๋กœ ์ „ํ™˜๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. ๋งˆ์น˜ ๋น™ํŒ์œ„์—์„œ ๋ฐฉํ–ฅ์ „ํ™˜ํ•˜๋“ฏ์ด ๋ฏธ๋„๋Ÿฌ์ ธ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๋˜๋Š” ๋Š๋‚Œ์ผ
๊ฒƒ์ด๋‹ค. ์ด๊ฒƒ์€ ๋ฐ”๋กœ Capsule ์ด๋ผ๋Š” ์˜ค๋ธŒ์ ํŠธ๊ฐ€ Rigidbody๋ผ๋Š” ๋ฌผ๋ฆฌ์  ์†์„ฑ์„ ๊ฐ€์ง€๋ฉด์„œ ํ˜„์žฌ์ƒํƒœ๋ฅผ
์œ ์ง€ํ•˜๋ ค๋Š” **๊ด€์„ฑ์ด ๋ฐ˜์˜๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค**. =>

[Rigidbody.velocity]
public Vector3 velocity;
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ๋ฒกํ„ฐ๊ฐ’์„ ๋„ฃ์–ด์„œ ํ•ด๋‹น ๋ฐฉํ–ฅ์œผ๋กœ ์›€์ง์ด๋„๋ก ํ•œ๋‹ค. 
์ฆ‰ Rigidbody๋ฅผ ๊ฐ€์ง„ ๋ฌผ์ฒด์— ์ฃผ์–ด์ง„ ์†๋„๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ 
์งˆ๋Ÿ‰๊ณผ ๊ด€์„ฑ๋“ค์„ ๋ฌด์‹œํ•˜๊ณ  ์ž…๋ ฅ๋ฐ›์€ ์†๋„๋กœ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฉ”์‹œ๋“œ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
private๋กœ ์„ ์–ธํ•œ ์ฐธ์กฐ๋ณ€์ˆ˜๋Š” ์ธ์ŠคํŽ™ํ„ฐ์—์„œ ๋ณผ ์ˆ˜ ์—†๋‹ค. ์Šคํฌ๋ฆฝํŠธ์— GetComponent<>()๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ
๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์•ˆ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ• ๋‹นํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.
public Rigidbody playerRigidbody;
private void Start()
{
	 playerRigidbody = GetComponent<Rigidbody>();
}
  • Character Controller ์ปดํฌ๋„ŒํŠธ
Rigidbody๊ฐ€ ์•„๋‹Œ Add Component > Physics > Character Controller ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
๋ฆฌ์ง€๋“œ๋ฐ”๋””๋Š” ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋งŽ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ์œค๋‹ˆํ‹ฐ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์ ์— ์ฐฉ์•ˆํ•ด ์ค‘๋ ฅ์ด๋‚˜ ์ถฉ๋Œ ๋“ฑ์˜
๊ฐ„๋‹จํ•œ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ๋งŒ์„ ํ•„์š”๋กœ ํ•˜๋Š” ์บ๋ฆญํ„ฐ ์ „์šฉ ํด๋ž˜์Šค์ธ character controller๊ฐ€ ์žˆ๋‹ค.
์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด์˜ ์ฝœ๋ผ์ด๋” ์ปดํฌ๋„ŒํŠธ๋Š” ์‚ญ์ œํ•œ๋‹ค.
์ค‘๋ ฅ์ด ์ ์šฉ๋œ ์ด๋™์„ ์œ„ํ•ด ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ํด๋ž˜์Šค์˜ Move() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ๋‹ค
  • Trigger(์ด์•Œ๋งŒ๋“ค๊ธฐ)
(1) Sphere - ๋ถ‰์€์ƒ‰ ๋จธํ‹ฐ๋ฆฌ์–ผ ์ ์šฉ
Position = 0, 1.5, -4
Scale = 0.3

(2) Rigidbody ์ถ”๊ฐ€ ํ›„ use Gravity ์ฒดํฌ๋ฅผ ํ•ด์ œ

[Collider]
**Collider ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌผ๋ฆฌ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์˜ค๋ธŒ์ ํŠธ์˜ ํ˜•ํƒœ๋ฅผ ์ •์˜ํ•œ๋‹ค.** 
์ฝœ๋ผ์ด๋”๋Š” ๋ณด์ด์ง€ ์•Š๋Š” ์š”์†Œ์ด๋ฏ€๋กœ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฉ”์‹œ์™€ ์ •ํ™•ํžˆ ๋™์ผํ•œ ๋ชจ์–‘์ผ ํ•„์š”๋Š” ์—†์œผ๋ฉฐ, ์‹ค์ œ๋กœ๋Š”
์ž„ํ”Œ๋ ˆ์ด ์‹œ์—๋Š” ๋Œ€๋žต์ ์ธ ๊ทผ์‚ฌ์น˜๋กœ๋„ ํฌ๊ฒŒ ๊ตฌ๋ถ„๋˜์ง€ ์•Š์œผ๋ฉฐ ๋” ํšจ์œจ์ ์ด๋‹ค.
[Collision]
Kinematic(๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๋Š” ์†์„ฑ) ์†์„ฑ์ด ๊บผ์ ธ์žˆ์„ ๋•Œ ๋ฐœ์ƒํ•œ๋‹ค. 
Kinematic์ด ์ผœ์ ธ ์žˆ์œผ๋ฉด ๋‚ด๋ถ€ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ์•ˆํ•ด์„œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜์œผ๋กœ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์—ฌ ์ถฉ๋Œํ•  ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ๋‹ค Collider๊ฐ€ ํ•„์š”ํ•˜๊ณ , ๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” Rigidbody๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

Enter : ์ด์•Œ์ด ๋‚ ์•„์™€ ๋ถ€๋”ช์น˜๋Š” ์ˆœ๊ฐ„ ๋ฐœ์ƒ(OnCollisionEnter)
Stay : ์ถฉ๋Œ ํ›„ ๋ถ™์–ด์žˆ๋Š” ์ƒํ™ฉ์—์„œ ๊ณ„์†์ ์œผ๋กœ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ(OnCollisionStay)
Exit : ๋ถ™์—ฌ์žˆ๋Š” ์ดํ›„ ๋–จ์–ด์ง€๋Š” ์ˆœ๊ฐ„ ์ด๋ฒคํŠธ(OnCollisionExit)

[Trigger]
Collision ์ดํ›„ ์ถฉ๋Œํ–ˆ๋‹ค๋Š”์‹ ํ˜ธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ.
Tirgger๊ฐ€ ์ฒดํฌ ๋˜์–ด ์žˆ๋‹ค๋ฉด ๋ฌผ๋ฆฌ์ ์ธ ํ˜„์ƒ์€ ์—†๊ณ  ์ถฉ๋Œํ–ˆ๋‹ค๊ณ ๋งŒ ์ธ์‹ํ•œ๋‹ค. 
์ถฉ๋Œ ํ•œ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ ํŠธ๋ฆฌ๊ฑฐ๋ฉด ํŠธ๋ฆฌ๊ฑฐ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
OnTriggerEnter, OnTriggerStay, OnTriggerExit ๊ฐ€ ์žˆ๋‹ค.

**OnCollision : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ํ†ตํ•ด ์ถฉ๋Œ ์ฒ˜๋ฆฌ, ๊ด€ํ†ต X, ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€ํ•˜๊ฐ€ ๋งŽ์ด ๊ฑธ๋ฆฐ๋‹ค.
OnTrigger : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ X, ๊ด€ํ†ต ๊ฐ€๋Šฅ, Collision ๋ณด๋‹ค ์—ฐ์‚ฐ์ด ์ ์–ด์„œ ํšจ์œจ์ ์ด๋‹ค.**

  • ํด๋ž˜์Šค์™€ ๊ฐ์ฒด

(1) ํด๋ž˜์Šค์™€ ์˜ค๋ธŒ์ ํŠธ๋Š” ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํ•ต์‹ฌ ๊ฐ์ฒด์ง€ํ–ฅ์€ ์‚ฌ๋žŒ์ด ํ˜„์‹ค ์„ธ์ƒ์„ ๋ณด๋Š” ๋ฐฉ์‹์— ๊ฐ€๊นŒ์šด ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์‚ฌ๋žŒ์€ ํ˜„์‹ค์˜ ์‚ฌ๋ฌผ์„ ‘๋ถ„ํ•ดํ•˜์—ฌ’ ์ƒ๊ฐํ•˜์ง€ ์•Š๊ณ  ์‚ฌ๋ฌผ์„ ‘์˜จ์ „ํ•œ ๋…๋ฆฝ์ฒด’๋กœ ์—ฌ๊ธฐ๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค. ์‚ฌ๋ฌผ์€ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๊ณ , ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒ์ƒ์†์˜ ์–ด๋–ค ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๋‹ค. ์‚ฌ๋žŒ, ๋™๋ฌผ, ๋ถ€๋ชจ, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๋ชจ๋‘ ์‚ฌ๋ฌผ์ด๋‹ค. ํ•˜์ง€๋งŒ ์ด์ค‘์— ๊ตฌ์ฒด์ ์ด์ง€์•Š๋Š” ๊ฒƒ์ด ์žˆ๋‹ค. ์‚ฌ๋žŒ์€ ๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹Œ ์ถ”์ƒ์ ์ธ ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ด๋ž€๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹ˆ๊ณ  ์ถ”์ƒ์  ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ธ ์‚ฌ๋ฌผ์„ ‘ํด๋ž˜์Šค’, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๊ตฌ์ฒด์ ์ธ ๊ฒƒ๋“ค์„ ‘๊ฐ์ฒด’๋ผ๊ณ  ํ•œ๋‹ค.

(2) ํด๋ž˜์Šค ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๋Œ€์ƒ์„ ์ถ”์ƒํ™”ํ•˜์—ฌ ๋Œ€์ƒ๊ณผ ๊ด€๋ จ๋œ ๋œ ๋ณ€์ˆ˜ & ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ํ‹€์ด๋‹ค.

ํ‹€์€ ๋ˆˆ์— ๋ณด์ด์ง€๋Š” ์•Š์ง€๋งŒ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

ํด๋ž˜์Šค๋Š” ์†์„ฑ๊ณผ ๊ธฐ๋Šฅ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

(3) ๊ฐ์ฒด ๋ฌผ๊ฑด์˜ ์„ค๊ณ„๋„์ธ ํด๋ž˜์Šค์™€ ๋‹ฌ๋ฆฌ ์˜ค๋ธŒ์ ํŠธ๋Š” ์‹ค์ฒด์ด๋‹ค.

‘์‚ฌ๋žŒ’์ด๋ผ๋Š” ํด๋ž˜์Šค๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ํด๋ž˜์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒ์„ฑํ•œ ์˜ค๋ธŒ์ ํŠธ๋Š” ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํด๋ž˜์Šค๋ผ๋Š” ํ‹€๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ฐ์–ด๋‚ด๋Š” ๊ฒƒ์„ ์ธ์Šคํ„ด์Šคํ™”ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์ธ์Šคํ„ด์Šคํ™”๋ฅผ์ด์šฉํ•ด ์ƒ์„ฑ๋œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ธ์Šคํ„ด์Šค๋ผ๊ณ ํ•œ๋‹ค.

๋˜ํ•œ, ์ธ์Šคํ„ด์Šคํ•œ ์˜ค๋ธŒ์ ํŠธ๋“ค์€ ์„œ๋กœ ๋…๋ฆฝ์ ์ด๋ฉฐ๊ตฌ๋ณ„ ๊ฐ€๋Šฅํ•œ ์‹ค์ฒด์ด๋‹ค.

  • Instantiate (์ธ์Šคํ„ด์Šค)

(1) ์ธ์Šคํ„ด์Šค ๋ณต์ œ Instantiate() ๋ฉ”์„œ๋“œ๋Š” ์›๋ณธ ์˜ค๋ธŒ์ ํŠธ(Prefab)๋ฅผ ๋ณต์ œํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์ฆ‰, ์ธ์Šคํ„ดํŠธํ™”๋ฅผ ํ•˜์—ฌ ์›๋ณธ์„ ๋ณต์ œํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ Instantiate(์›๋ณธ, ์œ„์น˜, ํšŒ์ „); ๋ณต์ œํ•  ์›๋ณธ, ์ด๋™ํ•  ์œ„์น˜, ์ด๋™ ๋ฐฉํ–ฅ์„ ์„ค์ •

(2) ์ธ์Šคํ„ด์Šค ์‚ญ์ œ Destroy(object, float time); Destroy() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค. float time ๋งŒํผ ์ง€์—ฐ ํ›„ ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค.

  • Random.Range()

(1) ๋žœ๋คํ•œ ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์œผ๋กœ ํƒ„์•Œ์„ ๊ณ„์† ์ƒ์„ฑ Random.Range() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅ์œผ๋กœ ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ์ˆœ์„œ๋Œ€๋กœ ๋ฐ›๊ณ , ๊ทธ ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. float ์„ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์™€ int ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์˜ ๋™์ž‘์ด ๋‹ค๋ฅด๋‹ค. Random.Range(0, 3) ๋Š” 0, 1, 2 ์ค‘ ํ•˜๋‚˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. Random.Range(0f, 3f)๋Š” 0์—์„œ๋ถ€ํ„ฐ 3f ์‚ฌ์ด์˜ float ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค. 0.5f

  • ์”ฌ์—์„œ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ
**โ— Find(“๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ด๋ฆ„”) - ๊ฐ€์žฅ ์ฒ˜์Œ ๊ฒ€์ƒ‰๋œ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindWithTag(“ํƒœ๊ทธ์ด๋ฆ„”) - ํƒœ๊ทธ๋กœ ๋Œ€์ƒ์„ ์ฐพ์Œ. ์ฒ˜์Œ ์ฐพ์€ ํ•˜๋‚˜์˜ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindGameObjectsWithTag(“๊ฐ™์€์ด๋ฆ„์˜ ํƒœ๊ทธ”) - ๊ฐ™์€ ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ›์Œ
โ— FindObjectOfType(ํƒ€์ž…๋ช…)
โ— FindObjectsOfType(ํƒ€์ž…๋ช…)**

(1) ์”ฌ์—์„œ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ FindObjectOfType() ๋ฉ”์„œ๋“œ player๊ฐ€ playerController(์ฝ”๋“œ) ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์žˆ๋‹ค. FindObjectOfType( ) ๋ฉ”์„œ๋“œ๋Š” ๊บพ์‡ <>์— ์–ด๋–ค ํƒ€์ž…์„ ๋ช…์‹œํ•˜๋ฉด ์”ฌ์— ๋ชจ๋“  ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ ํ•ด๋‹น ํƒ€์ž…์˜ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

  • ์˜ค๋ธŒ์ ํŠธ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ

(1) ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ–ฅํ•˜๋„๋ก ํƒ„์•Œ์„ ์ƒ์„ฑ

if(pController.enabled) {
	transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position -
	transform.position),1);
}

Die๋ถ€๋ถ„์— false๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

(2) ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ transform.LookAt() ๋ฉ”์„œ๋“œ๋Š” ๋‹ค๋ฅธ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์˜ transform๋ฅผ ๋ฐ›๋Š”๋‹ค. ์ž…๋ ฅ๋ฐ›์€ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์ž์‹ ์˜ transform ํšŒ์ „์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

//Update์—์„œ
bullet.transform.LookAt(target);

<aside> ๐Ÿ’€ ์ตœ์ข… - ๊ฒŒ์ž„๋งค๋‹ˆ์ € ์ œ์ž‘

๊ฒŒ์ž„ ๋งค๋‹ˆ์ €

  1. ๊ฒŒ์ž„์˜ค๋ฒ„๊ฐ€ ๋˜๋ฉด ‘Press R to Restart’ ๋ผ๋Š”๊ธ€์”จ๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.
  2. ๊ฒŒ์ž„์˜ค๋ฒ„ ์‹œ ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘

๋ฉ”์„œ๋“œ

  1. ์”ฌ์„ ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”using UnityEngine.SceneManagement; </aside>
  • gameManager
(1) Canvas > Text
 Transform Rect์—์„œ
- ์นด๋ฉ”๋ผ ๊ธฐ์ค€์œผ๋กœ ์บ”๋ฒ„์Šค๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณด์ผ ๊ฒƒ์ธ๊ฐ€?
- ์บ”๋ฒ„์Šค ์•ˆ์˜ ํ…์ŠคํŠธ, ๋ฒ„ํŠผ ๋“ค์˜ ์ •๋ ฌ : Alt ํ‚ค๋ฅผ ๋ˆ„๋ฅธ ์ƒํƒœ์—์„œ ๋ฐฐ์น˜
- ์ด ์ƒํƒœ์—์„œ ์‚ฌ์ด์ฆˆ ์กฐ์ ˆ
(2) Text GUI ์ถ”๊ฐ€ํ•˜๊ธฐ
- TimeText : “Time : 0” ์ƒ์กด ์‹œ๊ฐ„ ํ‘œํ˜„
- GameoverText : “Press R to Restart” ํ…์ŠคํŠธ ์ถ”๊ฐ€, ์ œ์ž‘ ํ›„ ๋น„ํ™œ์„ฑํ™”
- RecordText : “Best Record : 0” ํ…์ŠคํŠธ, GameoverText์˜ ์ž์‹์œผ๋กœ ๋งŒ๋“ค๊ธฐ
  • ํ˜„์žฌ๊นŒ์ง€์˜ ์ ์ˆ˜๋ฅผ ๋กœ์ปฌ๋กœ ์ €์žฅํ•˜๊ธฐ
(1) PlayerPref
Player Preference๋ผ๊ณ  ์ฝ์œผ๋ฉฐ ๊ฐ„๋‹จํ•œ ๋ฐฉ์‹์œผ๋กœ ์–ด๋–ค ์ˆ˜์น˜๋ฅผ ๋กœ์ปฌ์— ์ €์žฅํ•˜๊ณ  ๋‚˜์ค‘์— ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฉ”์„œ๋“œ๋ฅผ
์ œ๊ณตํ•œ๋‹ค.

*(2) ์ €์žฅํ•˜๊ธฐ
์‹ค์ˆ˜๊ฐ’์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.SetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.SetFloat(string key, float value);
์ •์ˆ˜๋Š” SetInt(string key, int value);
๋ฌธ์ž์—ด์€ SetString(string key, string value);*

(3) ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.GetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.GetFloat(string key);
์ •์ˆ˜๋Š” GetInt(string key);
๋ฌธ์ž์—ด์€ GetString(string key);
์ €์žฅ๋œ ๊ฐ’์ด ์—†๋‹ค๋ฉด ๊ธฐ๋ณธ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 0 ๋˜๋Š” ๋นˆ๋ฌธ์ž์—ด

(4) ์ด์ „์— ์ €์žฅํ•œ ๊ฐ’์ด ์žˆ๋Š”์ง€
HasKey(string key);
  • ๋ฐฉํ–ฅ ๋ฒกํ„ฐ = ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)

๋ฐฉํ–ฅ ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•œ๋‹ค.

ํฌ๊ธฐ๊ฐ€ 1์ด๋ฏ€๋กœ ๋ฐฉํ–ฅ์€ ๊ฐ™์ง€๋งŒ, ํฌ๊ธฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฒกํ„ฐ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ธฐ์ค€์œผ๋กœ ์‚ผ์„ ์ˆ˜ ์žˆ๋‹ค. (1, -1)์˜ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋ฅผ ๊ตฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋ฒกํ„ฐ์˜ ์‹œ์ž‘์ ์—์„œ ๋ฐ˜์ง€๋ฆ„์ด 1์ธ ์›์„ ๊ทธ๋ ค์„œ(1, -1)์˜ ์› ๋ฐ”๊นฅ ๋ถ€๋ถ„์„ ์ž˜๋ผ๋‚ธ๋‹ค. (๋ฐฉํ–ฅ์€ ์œ ์ง€ํ•˜๋ฉด์„œ) ๋ฒกํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๋ฒกํ„ฐ ์ •๊ทœํ™”์ด๋‹ค.

์™œ ๊ธธ์ด๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ผ๊นŒ? ๋ฐฉํ–ฅ์˜ ๊ฐ’์ด ์†๋„์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์น˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์ด๋ผ๋Š” ํ‘œํ˜„์œผ๋กœ๋Š” ์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ ์–ผ๋งˆ๋งŒํผ์˜ ์†๋ ฅ์„๊ฐ€์ง€๋Š”์ง€ ๋– ์˜ฌ๋ฆฌ๊ธฐ ํž˜๋“ค๋‹ค. ์ด๋•Œ (3, -3)์„ ์ˆœ์ˆ˜ํ•œ ๋ฐฉํ–ฅ๊ณผ ์ˆœ์ˆ˜ํ•œ ์†๋ ฅ์„ ๋‚˜๋ˆ„์–ด ํ‘œํ˜„ํ•˜๋ฉด ๋ฐฉํ–ฅ๊ณผ ์†๋„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. (3, -3) = ๋ฐฉํ–ฅ * ์†๋ ฅ ๋˜๋Š” ์ด๋™๊ฑฐ๋ฆฌ ๋ฒกํ„ฐ์˜ ์Šค์นผ๋ผ ๊ณฑ์„ ๋ฐฐ์› ๊ณ  ๋•Œ๋ฌธ์— (3, -3)๋Š” (1, -1)์˜ 3๋ฐฐ์— ํ•ด๋‹น๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋ ๊ฒƒ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์†๋ ฅ ์ž์ฒด๋ฅผ ํ‘œํ˜„ํ•˜์ง€ ๋ชปํ•œ๋‹ค. ์†๋ ฅ์ด 3์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. (1, -1)์˜ ํฌ๊ธฐ(magnitude)๋Š” 1.414… ์ด๊ธฐ๋•Œ๋ฌธ์ด๋‹ค. ‘A์˜ ๋ฐฉํ–ฅ์œผ๋กœ B๋งŒํผ์˜ ์†๋ ฅ’์„ ‘๋ฒกํ„ฐA * ์Šค์นผ๋ผB’๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฒกํ„ฐA๋Š” 1์ด ๋˜์ง€ ์•Š์œผ๋ฉด ์‹ค์ œ ์†๋ ฅ์€ B๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค.

๋”ฐ๋ผ์„œ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ฆ‰ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ๋‹ค. ๊ฒŒ์ž„์—์„œ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ ์˜ ์œ„์น˜๋ฅผ ํŒŒ์•…ํ•˜๊ณ  ์œ„์น˜์˜ ๋ฒกํ„ฐ ๊ฐ’(๋ฒกํ„ฐ C)์„ ์•Œ๊ณ  ์žˆ์„ ๋•Œ ๊ทธ์— ๋งž๋Š” ๊ฐ’์œผ๋กœ ๊ณ„์† ์•ž์œผ๋กœ ๋‚˜์•„๊ฐ„๋‹ค๋ฉด,

๋ฒกํ„ฐC์˜ ๊ฐ’์— ๋”ฐ๋ผ ์–ด๋Š ๋•Œ๋Š” ๋นจ๋ผ์ง€๊ธฐ๋„ ๋˜๋Š” ๋Š๋ ค์ง€๊ธฐ๋„ ํ•œ๋‹ค. ์ด๋Ÿฐ ์ƒํ™ฉ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ฒกํ„ฐ์˜ ๊ธธ์ด๋ฅผ 1๋กœ ์ •๊ทœํ™”ํ•œ๋‹ค.

  • normailzed ์ ์šฉํ›„ ๋น„๊ต
float speed = 2f;
Vector3 varPose = new Vector3(1,1,1);
//์ด์ „์œ„์น˜
Vector3 prePose;
Vector3 parePose;
float magFloat;

void Update()
{
	prePose = transform.position;
	**transform.Translate(varPose.normalized * speed * Time.deltaTime);** 
	parePose = transform.position - prePose;
	magFloat = parePose.magnitude;
	Debug.Log(magFloat);
}
  • ํ˜„์žฌ ์œ„์น˜์—์„œ ๋ชฉ์ ์ง€๋กœ ํ–ฅํ•˜๋Š” ๋ฐฉํ–ฅ
public GameObject pos1;
public GameObject pos2;
Vector3 objectPos1;
Vector3 objectPos2;
float speed = 10;
Vector3 direction;
float magTarget;
Vector3 nowSpeed;

void Update()
{
	objectPos1 = pos1.transform.position;
	objectPos2 = transform.position;
	magTarget = (objectPos1 - objectPos2).magnitude;
	direction = (objectPos1 - objectPos2).normalized;

	if (magTarget < 10 )
	{
		nowSpeed = direction * speed * Time.deltaTime;
	}
	else
	{
		nowSpeed = new Vector3(0,0,0);
	}

	transform.Translate(nowSpeed);
}

๋ณ€์ˆ˜, ํ•จ์ˆ˜ ๋…ธ๋ž€์ƒ‰ ์ฝ๊ธฐ


  • ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•
**(1) Input.GetKey**
GetKey, GetKeyDown, GetKeyUp

if(Input.GetKey(“Name”))
{ //๋ช…๋ น}
right, left, up, down, space, tab, delete, a, b, c, 1, 2, 3… ๋“ฑ

**(2) Name๋ถ€๋ถ„์— KeyCode**

if(Input.GetKey(KeyCode.UpArrow))
{ //๋ช…๋ น }
Input.GetKeyDown(“space”) == Input.GetKeyDown(KeyCode.Space)
  • ๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ
**(2) Input.GetButton**
GetButton, GetButtonDown, GetButtonUp
if(Input.**GetButtonDown**(“ButtonName”))
{ //๋ช…๋ น }
ButtonName์„ ๋ˆ„๋ฅด๋Š” ๋™์•ˆ true๋กœ ๋ฌด๊ธฐ๋ฅ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฒ„ํŠผ ํŠธ๋ฆฌ๊ฑฐ๋กœ ์‚ฌ์šฉํ• ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
Edit > Project Setting > Input์—์„œ ๋ฏธ๋ฆฌ ์„ค์ •๋œ ButtonName์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ‘Fire1’๋Š” ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ

**(2) Input.GetMouseButton**
GetMouseButton, GetMouseButtonDown, GetMouseButtonUp
if (Input.**GetMouseButtonDown**(0))
{
	print("๋งˆ์šฐ์Šค๋‹ค์šด");
}

**GetMouseButtonDown(0) : ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(1) : ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(2) : ๋งˆ์šฐ์Šค ์ค‘์•™(ํœ ) ๋ฒ„ํŠผ**
  • Rigidbody
Player ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์›€์ง์ž„์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•ด Rigidbody๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
Add Component > Physics > Rigidbody

- ์ค‘๋ ฅ Use Gravity ๋ฅผ ์ฒดํฌํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ฐ‘์œผ๋กœ ๋–จ์–ด์ง„๋‹ค. 
Mass๊ฐ’์— ๋”ฐ๋ผ ๋–จ์–ด์ง€๋Š” ์ค‘๋Ÿ‰ ํ‘œํ˜„ํ•œ๋‹ค. 

-์บก์Š์ฒ˜๋Ÿผ ๋ฐ”๋‹ฅ๋ฉด์ด ๊ณก์„ ์ผ ๊ฒฝ์šฐ ์ค‘๋ ฅ์œผ๋กœ ์˜ํ–ฅ์œผ๋กœ ์“ฐ๋Ÿฌ์งˆ ์ˆ˜ ์žˆ๋‹ค. 
Constaints์—์„œ ์œ„๋กœ ํŠ•๊ฒจ๋‚˜๊ฐ€์ง€ ์•Š๋„๋ก Freeze Position์˜ Y ์ฒดํฌํ•œ๋‹ค.
์ถฉ๋Œ ์ดํ›„ ์›ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐ”๋ผ๋ณด๋„๋ก Freeze Rotation์˜ X์™€ Z๋ฅผ ์ฒดํฌํ•œ๋‹ค.

- ์ถฉ๋Œ์ฒดํฌ๋Š” Collider ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋Š” ๋ชจ๋‘ ์ถฉ๋Œ ์ฒดํฌ๋ฅผ ํ•œ๋‹ค. 
๋‹จ, Is Kinematic์ด ์ฒดํฌ๊ฐ€ ๋˜๋ฉด ๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๊ฒŒ ๋œ๋‹ค.

ํ†ตํ†ตํŠ€๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ(๋ฌผ๋ฆฌ ์žฌ์งˆ ๋งŒ๋“ค์–ด์„œ ์ ์šฉํ•˜๊ธฐ)
- Freeze Position์˜ Y ์ฒดํฌ ํ’€๊ธฐ
- Project์ฐฝ์˜ Create > Physic Material ์ถ”๊ฐ€, Bounciness ๊ฐ’์„ 1
- Player์˜ Collider์˜ Material์— ์ถ”๊ฐ€ํ•œ๋‹ค.
  • Rigidbody์— ํž˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™
[Rigidbody.AddForce]
public void AddForce(float x, float y, float z, forceMode);
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ํž˜์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํž˜์˜ ๋ฐฉํ–ฅ์„ ๋”ฐ๋ผ ์ผ์ •ํ•œ ํž˜์„ ์ง€์†์ ์œผ๋กœ ๋ถ€์—ฌํ•œ๋‹ค. 
forceMode๋ฅผ ์ง€์ •ํ•˜๋ฉด ๊ฐ€์†(Acceleration), ์ถฉ๊ฒฉ(Impulse), ์†๋„๋ณ€๊ฒฝ(Velocity Change)๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
์—…๋ฐ์ดํŠธ ๋ฌธ์—์„œ ๋ฐฉํ–ฅํ‚ค๋กœ ํž˜์ด ๊ฐ€ํ•ด์ง€๋„๋ก ์ž‘์„ฑํ•˜๊ฒŒ ๋œ๋‹ค
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐธ์กฐ๋ณ€์ˆ˜๋กœ ์กฐ์ ˆํ•˜๊ธฐ
์ฐธ์กฐ ํƒ€์ž…์œผ๋กœ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ ์กฐ์ข… ๊ฐ€๋Šฅํ•˜๋‹ค. .์ฐธ์กฐ ๋ณ€์ˆ˜๋Š” ์‹ค์ฒด๋Š” ์•„๋‹ˆ์ง€๋งŒ, ์‹ค์ฒด์ฒ˜๋Ÿผ
์ฐธ์กฐ๊ฐ’์„ ์ €์žฅํ•œ๋‹ค. ์ด๋กœ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์Šคํฌ๋ฆฝํŠธ์—์„œ ์ฐธ์กฐ ํƒ€์ž… ๋ณ€์ˆ˜๋กœ ์„ ์–ธ, ์ ‘๊ทผํ•˜์—ฌ, ์ œ์–ด
๊ฐ€๋Šฅํ•˜๋‹ค.
public Rigidbody playerRigidbody;
๋กœ ์„ ์–ธํ•œ ํ›„์—
playerRigidbody.AddForce(0, 500, 0);

<aside> ๐Ÿ’€ ๋ฌธ์ œ

-Rigidbody ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ง์ ‘ ํ• ๋‹นํ•˜์ง€ ์•Š์€ ๋ฐฉ๋ฒ•์€?

: AddFoce()๋Š” ์ ์ง„์ ์œผ๋กœ ์†๋„๊ฐ€ ์ฆ๊ฐ€๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋นจ๋ผ์ง€๋Š”๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค.

: ์ž…๋ ฅ ๊ฐ์ง€ ์ฝ”๋“œ๊ฐ€ ๋ณต์žกํ•˜๋‹ค. ์ฆ‰, IF ๋ฌธ์„ ๋„ˆ๋ฌด ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

</aside>

  • ๋งˆ์šฐ์Šค์™€ ์กฐ์ด์Šคํ‹ฑ
(1) Axis(์ถ•์„ ์ด์šฉ)
Input.GetAxis(“Horizontal”) 
Input.GetAxis(“Vertical”)
Axis์€ ์›€์ง์ด์ง€ ์•Š์„ ๋•Œ๋Š” 0, ์ˆ˜ํ‰์—์„œ ์™ผ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด -1, ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด 1 ์ด๋ผ๋Š” ๊ฐ’
์ˆ˜์ง์—์„œ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€๋ฉด 1, ๋‚ด๋ ค๊ฐ€๋ฉด -1 ์ด๋ผ๋Š” ๊ฐ’
“Horizontal”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์™ผ์ชฝ ๋ฐฉํ–ฅํ‚ค, A | ์–‘์˜ ๋ฐฉํ–ฅ : ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅํ‚ค, D 
“Vertical”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์•„๋ž˜์ชฝ ๋ฐฉํ–ฅํ‚ค, S | ์–‘์˜ ๋ฐฉํ–ฅ : ์œ„์ชฝ ๋ฐฉํ–ฅํ‚ค, W 

(2) ๋งˆ์šฐ์Šค ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ์ด๋™ ํ™•์ธ
Input.GetAxis(“Mouse X”)
Input.GetAxis(“Mouse Y”)
  • Rigidbody์˜ ์ด๋™์„ ์ผ์ •ํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ
์ฒ˜์Œ ์›€์ง์ผ ๋•Œ๋Š” ์ž˜ ์›€์ง์ด์ง€๋งŒ, ์ฒœ์ฒœํžˆ ๊ฐ€๋‹ค๊ฐ€ ๋’ค๋กœ ๊ฐˆ์ˆ˜๋ก ๋นจ๋ผ์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์›€์ง์ด๋‹ค ๋ฐฉํ–ฅ ์ „ํ™˜์„
ํ•ด๋ณด๋ฉด ๋ฐ”๋กœ ์ „ํ™˜๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. ๋งˆ์น˜ ๋น™ํŒ์œ„์—์„œ ๋ฐฉํ–ฅ์ „ํ™˜ํ•˜๋“ฏ์ด ๋ฏธ๋„๋Ÿฌ์ ธ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๋˜๋Š” ๋Š๋‚Œ์ผ
๊ฒƒ์ด๋‹ค. ์ด๊ฒƒ์€ ๋ฐ”๋กœ Capsule ์ด๋ผ๋Š” ์˜ค๋ธŒ์ ํŠธ๊ฐ€ Rigidbody๋ผ๋Š” ๋ฌผ๋ฆฌ์  ์†์„ฑ์„ ๊ฐ€์ง€๋ฉด์„œ ํ˜„์žฌ์ƒํƒœ๋ฅผ
์œ ์ง€ํ•˜๋ ค๋Š” **๊ด€์„ฑ์ด ๋ฐ˜์˜๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค**. =>

[Rigidbody.velocity]
public Vector3 velocity;
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ๋ฒกํ„ฐ๊ฐ’์„ ๋„ฃ์–ด์„œ ํ•ด๋‹น ๋ฐฉํ–ฅ์œผ๋กœ ์›€์ง์ด๋„๋ก ํ•œ๋‹ค. 
์ฆ‰ Rigidbody๋ฅผ ๊ฐ€์ง„ ๋ฌผ์ฒด์— ์ฃผ์–ด์ง„ ์†๋„๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ 
์งˆ๋Ÿ‰๊ณผ ๊ด€์„ฑ๋“ค์„ ๋ฌด์‹œํ•˜๊ณ  ์ž…๋ ฅ๋ฐ›์€ ์†๋„๋กœ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฉ”์‹œ๋“œ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
private๋กœ ์„ ์–ธํ•œ ์ฐธ์กฐ๋ณ€์ˆ˜๋Š” ์ธ์ŠคํŽ™ํ„ฐ์—์„œ ๋ณผ ์ˆ˜ ์—†๋‹ค. ์Šคํฌ๋ฆฝํŠธ์— GetComponent<>()๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ
๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์•ˆ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ• ๋‹นํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.
public Rigidbody playerRigidbody;
private void Start()
{
	 playerRigidbody = GetComponent<Rigidbody>();
}
  • Character Controller ์ปดํฌ๋„ŒํŠธ
Rigidbody๊ฐ€ ์•„๋‹Œ Add Component > Physics > Character Controller ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
๋ฆฌ์ง€๋“œ๋ฐ”๋””๋Š” ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋งŽ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ์œค๋‹ˆํ‹ฐ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์ ์— ์ฐฉ์•ˆํ•ด ์ค‘๋ ฅ์ด๋‚˜ ์ถฉ๋Œ ๋“ฑ์˜
๊ฐ„๋‹จํ•œ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ๋งŒ์„ ํ•„์š”๋กœ ํ•˜๋Š” ์บ๋ฆญํ„ฐ ์ „์šฉ ํด๋ž˜์Šค์ธ character controller๊ฐ€ ์žˆ๋‹ค.
์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด์˜ ์ฝœ๋ผ์ด๋” ์ปดํฌ๋„ŒํŠธ๋Š” ์‚ญ์ œํ•œ๋‹ค.
์ค‘๋ ฅ์ด ์ ์šฉ๋œ ์ด๋™์„ ์œ„ํ•ด ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ํด๋ž˜์Šค์˜ Move() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ๋‹ค
  • Trigger(์ด์•Œ๋งŒ๋“ค๊ธฐ)
(1) Sphere - ๋ถ‰์€์ƒ‰ ๋จธํ‹ฐ๋ฆฌ์–ผ ์ ์šฉ
Position = 0, 1.5, -4
Scale = 0.3

(2) Rigidbody ์ถ”๊ฐ€ ํ›„ use Gravity ์ฒดํฌ๋ฅผ ํ•ด์ œ

[Collider]
**Collider ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌผ๋ฆฌ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์˜ค๋ธŒ์ ํŠธ์˜ ํ˜•ํƒœ๋ฅผ ์ •์˜ํ•œ๋‹ค.** 
์ฝœ๋ผ์ด๋”๋Š” ๋ณด์ด์ง€ ์•Š๋Š” ์š”์†Œ์ด๋ฏ€๋กœ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฉ”์‹œ์™€ ์ •ํ™•ํžˆ ๋™์ผํ•œ ๋ชจ์–‘์ผ ํ•„์š”๋Š” ์—†์œผ๋ฉฐ, ์‹ค์ œ๋กœ๋Š”
์ž„ํ”Œ๋ ˆ์ด ์‹œ์—๋Š” ๋Œ€๋žต์ ์ธ ๊ทผ์‚ฌ์น˜๋กœ๋„ ํฌ๊ฒŒ ๊ตฌ๋ถ„๋˜์ง€ ์•Š์œผ๋ฉฐ ๋” ํšจ์œจ์ ์ด๋‹ค.
[Collision]
Kinematic(๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๋Š” ์†์„ฑ) ์†์„ฑ์ด ๊บผ์ ธ์žˆ์„ ๋•Œ ๋ฐœ์ƒํ•œ๋‹ค. 
Kinematic์ด ์ผœ์ ธ ์žˆ์œผ๋ฉด ๋‚ด๋ถ€ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ์•ˆํ•ด์„œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜์œผ๋กœ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์—ฌ ์ถฉ๋Œํ•  ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ๋‹ค Collider๊ฐ€ ํ•„์š”ํ•˜๊ณ , ๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” Rigidbody๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

Enter : ์ด์•Œ์ด ๋‚ ์•„์™€ ๋ถ€๋”ช์น˜๋Š” ์ˆœ๊ฐ„ ๋ฐœ์ƒ(OnCollisionEnter)
Stay : ์ถฉ๋Œ ํ›„ ๋ถ™์–ด์žˆ๋Š” ์ƒํ™ฉ์—์„œ ๊ณ„์†์ ์œผ๋กœ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ(OnCollisionStay)
Exit : ๋ถ™์—ฌ์žˆ๋Š” ์ดํ›„ ๋–จ์–ด์ง€๋Š” ์ˆœ๊ฐ„ ์ด๋ฒคํŠธ(OnCollisionExit)

[Trigger]
Collision ์ดํ›„ ์ถฉ๋Œํ–ˆ๋‹ค๋Š”์‹ ํ˜ธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ.
Tirgger๊ฐ€ ์ฒดํฌ ๋˜์–ด ์žˆ๋‹ค๋ฉด ๋ฌผ๋ฆฌ์ ์ธ ํ˜„์ƒ์€ ์—†๊ณ  ์ถฉ๋Œํ–ˆ๋‹ค๊ณ ๋งŒ ์ธ์‹ํ•œ๋‹ค. 
์ถฉ๋Œ ํ•œ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ ํŠธ๋ฆฌ๊ฑฐ๋ฉด ํŠธ๋ฆฌ๊ฑฐ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
OnTriggerEnter, OnTriggerStay, OnTriggerExit ๊ฐ€ ์žˆ๋‹ค.

**OnCollision : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ํ†ตํ•ด ์ถฉ๋Œ ์ฒ˜๋ฆฌ, ๊ด€ํ†ต X, ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€ํ•˜๊ฐ€ ๋งŽ์ด ๊ฑธ๋ฆฐ๋‹ค.
OnTrigger : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ X, ๊ด€ํ†ต ๊ฐ€๋Šฅ, Collision ๋ณด๋‹ค ์—ฐ์‚ฐ์ด ์ ์–ด์„œ ํšจ์œจ์ ์ด๋‹ค.**

  • ํด๋ž˜์Šค์™€ ๊ฐ์ฒด

(1) ํด๋ž˜์Šค์™€ ์˜ค๋ธŒ์ ํŠธ๋Š” ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํ•ต์‹ฌ ๊ฐ์ฒด์ง€ํ–ฅ์€ ์‚ฌ๋žŒ์ด ํ˜„์‹ค ์„ธ์ƒ์„ ๋ณด๋Š” ๋ฐฉ์‹์— ๊ฐ€๊นŒ์šด ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์‚ฌ๋žŒ์€ ํ˜„์‹ค์˜ ์‚ฌ๋ฌผ์„ ‘๋ถ„ํ•ดํ•˜์—ฌ’ ์ƒ๊ฐํ•˜์ง€ ์•Š๊ณ  ์‚ฌ๋ฌผ์„ ‘์˜จ์ „ํ•œ ๋…๋ฆฝ์ฒด’๋กœ ์—ฌ๊ธฐ๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค. ์‚ฌ๋ฌผ์€ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๊ณ , ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒ์ƒ์†์˜ ์–ด๋–ค ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๋‹ค. ์‚ฌ๋žŒ, ๋™๋ฌผ, ๋ถ€๋ชจ, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๋ชจ๋‘ ์‚ฌ๋ฌผ์ด๋‹ค. ํ•˜์ง€๋งŒ ์ด์ค‘์— ๊ตฌ์ฒด์ ์ด์ง€์•Š๋Š” ๊ฒƒ์ด ์žˆ๋‹ค. ์‚ฌ๋žŒ์€ ๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹Œ ์ถ”์ƒ์ ์ธ ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ด๋ž€๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹ˆ๊ณ  ์ถ”์ƒ์  ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ธ ์‚ฌ๋ฌผ์„ ‘ํด๋ž˜์Šค’, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๊ตฌ์ฒด์ ์ธ ๊ฒƒ๋“ค์„ ‘๊ฐ์ฒด’๋ผ๊ณ  ํ•œ๋‹ค.

(2) ํด๋ž˜์Šค ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๋Œ€์ƒ์„ ์ถ”์ƒํ™”ํ•˜์—ฌ ๋Œ€์ƒ๊ณผ ๊ด€๋ จ๋œ ๋œ ๋ณ€์ˆ˜ & ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ํ‹€์ด๋‹ค.

ํ‹€์€ ๋ˆˆ์— ๋ณด์ด์ง€๋Š” ์•Š์ง€๋งŒ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

ํด๋ž˜์Šค๋Š” ์†์„ฑ๊ณผ ๊ธฐ๋Šฅ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

(3) ๊ฐ์ฒด ๋ฌผ๊ฑด์˜ ์„ค๊ณ„๋„์ธ ํด๋ž˜์Šค์™€ ๋‹ฌ๋ฆฌ ์˜ค๋ธŒ์ ํŠธ๋Š” ์‹ค์ฒด์ด๋‹ค.

‘์‚ฌ๋žŒ’์ด๋ผ๋Š” ํด๋ž˜์Šค๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ํด๋ž˜์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒ์„ฑํ•œ ์˜ค๋ธŒ์ ํŠธ๋Š” ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํด๋ž˜์Šค๋ผ๋Š” ํ‹€๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ฐ์–ด๋‚ด๋Š” ๊ฒƒ์„ ์ธ์Šคํ„ด์Šคํ™”ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์ธ์Šคํ„ด์Šคํ™”๋ฅผ์ด์šฉํ•ด ์ƒ์„ฑ๋œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ธ์Šคํ„ด์Šค๋ผ๊ณ ํ•œ๋‹ค.

๋˜ํ•œ, ์ธ์Šคํ„ด์Šคํ•œ ์˜ค๋ธŒ์ ํŠธ๋“ค์€ ์„œ๋กœ ๋…๋ฆฝ์ ์ด๋ฉฐ๊ตฌ๋ณ„ ๊ฐ€๋Šฅํ•œ ์‹ค์ฒด์ด๋‹ค.

  • Instantiate (์ธ์Šคํ„ด์Šค)

(1) ์ธ์Šคํ„ด์Šค ๋ณต์ œ Instantiate() ๋ฉ”์„œ๋“œ๋Š” ์›๋ณธ ์˜ค๋ธŒ์ ํŠธ(Prefab)๋ฅผ ๋ณต์ œํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์ฆ‰, ์ธ์Šคํ„ดํŠธํ™”๋ฅผ ํ•˜์—ฌ ์›๋ณธ์„ ๋ณต์ œํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ Instantiate(์›๋ณธ, ์œ„์น˜, ํšŒ์ „); ๋ณต์ œํ•  ์›๋ณธ, ์ด๋™ํ•  ์œ„์น˜, ์ด๋™ ๋ฐฉํ–ฅ์„ ์„ค์ •

(2) ์ธ์Šคํ„ด์Šค ์‚ญ์ œ Destroy(object, float time); Destroy() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค. float time ๋งŒํผ ์ง€์—ฐ ํ›„ ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค.

  • Random.Range()

(1) ๋žœ๋คํ•œ ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์œผ๋กœ ํƒ„์•Œ์„ ๊ณ„์† ์ƒ์„ฑ Random.Range() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅ์œผ๋กœ ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ์ˆœ์„œ๋Œ€๋กœ ๋ฐ›๊ณ , ๊ทธ ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. float ์„ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์™€ int ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์˜ ๋™์ž‘์ด ๋‹ค๋ฅด๋‹ค. Random.Range(0, 3) ๋Š” 0, 1, 2 ์ค‘ ํ•˜๋‚˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. Random.Range(0f, 3f)๋Š” 0์—์„œ๋ถ€ํ„ฐ 3f ์‚ฌ์ด์˜ float ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค. 0.5f

  • ์”ฌ์—์„œ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ
**โ— Find(“๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ด๋ฆ„”) - ๊ฐ€์žฅ ์ฒ˜์Œ ๊ฒ€์ƒ‰๋œ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindWithTag(“ํƒœ๊ทธ์ด๋ฆ„”) - ํƒœ๊ทธ๋กœ ๋Œ€์ƒ์„ ์ฐพ์Œ. ์ฒ˜์Œ ์ฐพ์€ ํ•˜๋‚˜์˜ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindGameObjectsWithTag(“๊ฐ™์€์ด๋ฆ„์˜ ํƒœ๊ทธ”) - ๊ฐ™์€ ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ›์Œ
โ— FindObjectOfType(ํƒ€์ž…๋ช…)
โ— FindObjectsOfType(ํƒ€์ž…๋ช…)**

(1) ์”ฌ์—์„œ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ FindObjectOfType() ๋ฉ”์„œ๋“œ player๊ฐ€ playerController(์ฝ”๋“œ) ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์žˆ๋‹ค. FindObjectOfType( ) ๋ฉ”์„œ๋“œ๋Š” ๊บพ์‡ <>์— ์–ด๋–ค ํƒ€์ž…์„ ๋ช…์‹œํ•˜๋ฉด ์”ฌ์— ๋ชจ๋“  ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ ํ•ด๋‹น ํƒ€์ž…์˜ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

  • ์˜ค๋ธŒ์ ํŠธ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ

(1) ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ–ฅํ•˜๋„๋ก ํƒ„์•Œ์„ ์ƒ์„ฑ

if(pController.enabled) {
	transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position -
	transform.position),1);
}

Die๋ถ€๋ถ„์— false๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

(2) ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ transform.LookAt() ๋ฉ”์„œ๋“œ๋Š” ๋‹ค๋ฅธ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์˜ transform๋ฅผ ๋ฐ›๋Š”๋‹ค. ์ž…๋ ฅ๋ฐ›์€ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์ž์‹ ์˜ transform ํšŒ์ „์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

//Update์—์„œ
bullet.transform.LookAt(target);

<aside> ๐Ÿ’€ ์ตœ์ข… - ๊ฒŒ์ž„๋งค๋‹ˆ์ € ์ œ์ž‘

๊ฒŒ์ž„ ๋งค๋‹ˆ์ €

  1. ๊ฒŒ์ž„์˜ค๋ฒ„๊ฐ€ ๋˜๋ฉด ‘Press R to Restart’ ๋ผ๋Š”๊ธ€์”จ๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.
  2. ๊ฒŒ์ž„์˜ค๋ฒ„ ์‹œ ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘

๋ฉ”์„œ๋“œ

  1. ์”ฌ์„ ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”using UnityEngine.SceneManagement; </aside>
  • gameManager
(1) Canvas > Text
 Transform Rect์—์„œ
- ์นด๋ฉ”๋ผ ๊ธฐ์ค€์œผ๋กœ ์บ”๋ฒ„์Šค๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณด์ผ ๊ฒƒ์ธ๊ฐ€?
- ์บ”๋ฒ„์Šค ์•ˆ์˜ ํ…์ŠคํŠธ, ๋ฒ„ํŠผ ๋“ค์˜ ์ •๋ ฌ : Alt ํ‚ค๋ฅผ ๋ˆ„๋ฅธ ์ƒํƒœ์—์„œ ๋ฐฐ์น˜
- ์ด ์ƒํƒœ์—์„œ ์‚ฌ์ด์ฆˆ ์กฐ์ ˆ
(2) Text GUI ์ถ”๊ฐ€ํ•˜๊ธฐ
- TimeText : “Time : 0” ์ƒ์กด ์‹œ๊ฐ„ ํ‘œํ˜„
- GameoverText : “Press R to Restart” ํ…์ŠคํŠธ ์ถ”๊ฐ€, ์ œ์ž‘ ํ›„ ๋น„ํ™œ์„ฑํ™”
- RecordText : “Best Record : 0” ํ…์ŠคํŠธ, GameoverText์˜ ์ž์‹์œผ๋กœ ๋งŒ๋“ค๊ธฐ
  • ํ˜„์žฌ๊นŒ์ง€์˜ ์ ์ˆ˜๋ฅผ ๋กœ์ปฌ๋กœ ์ €์žฅํ•˜๊ธฐ
(1) PlayerPref
Player Preference๋ผ๊ณ  ์ฝ์œผ๋ฉฐ ๊ฐ„๋‹จํ•œ ๋ฐฉ์‹์œผ๋กœ ์–ด๋–ค ์ˆ˜์น˜๋ฅผ ๋กœ์ปฌ์— ์ €์žฅํ•˜๊ณ  ๋‚˜์ค‘์— ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฉ”์„œ๋“œ๋ฅผ
์ œ๊ณตํ•œ๋‹ค.

*(2) ์ €์žฅํ•˜๊ธฐ
์‹ค์ˆ˜๊ฐ’์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.SetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.SetFloat(string key, float value);
์ •์ˆ˜๋Š” SetInt(string key, int value);
๋ฌธ์ž์—ด์€ SetString(string key, string value);*

(3) ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.GetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.GetFloat(string key);
์ •์ˆ˜๋Š” GetInt(string key);
๋ฌธ์ž์—ด์€ GetString(string key);
์ €์žฅ๋œ ๊ฐ’์ด ์—†๋‹ค๋ฉด ๊ธฐ๋ณธ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 0 ๋˜๋Š” ๋นˆ๋ฌธ์ž์—ด

(4) ์ด์ „์— ์ €์žฅํ•œ ๊ฐ’์ด ์žˆ๋Š”์ง€
HasKey(string key);
  • ๋ฐฉํ–ฅ ๋ฒกํ„ฐ = ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)

๋ฐฉํ–ฅ ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ(Normalized Vector)๋ผ๊ณ  ๋ถ€๋ฅด๊ธฐ๋„ ํ•œ๋‹ค.

ํฌ๊ธฐ๊ฐ€ 1์ด๋ฏ€๋กœ ๋ฐฉํ–ฅ์€ ๊ฐ™์ง€๋งŒ, ํฌ๊ธฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฒกํ„ฐ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ธฐ์ค€์œผ๋กœ ์‚ผ์„ ์ˆ˜ ์žˆ๋‹ค. (1, -1)์˜ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋ฅผ ๊ตฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋ฒกํ„ฐ์˜ ์‹œ์ž‘์ ์—์„œ ๋ฐ˜์ง€๋ฆ„์ด 1์ธ ์›์„ ๊ทธ๋ ค์„œ(1, -1)์˜ ์› ๋ฐ”๊นฅ ๋ถ€๋ถ„์„ ์ž˜๋ผ๋‚ธ๋‹ค. (๋ฐฉํ–ฅ์€ ์œ ์ง€ํ•˜๋ฉด์„œ) ๋ฒกํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๋ฒกํ„ฐ ์ •๊ทœํ™”์ด๋‹ค.

์™œ ๊ธธ์ด๋ฅผ 1๋กœ ๋งŒ๋“œ๋Š” ๊ฒƒ์ผ๊นŒ? ๋ฐฉํ–ฅ์˜ ๊ฐ’์ด ์†๋„์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์น˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์ด๋ผ๋Š” ํ‘œํ˜„์œผ๋กœ๋Š” ์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ ์–ผ๋งˆ๋งŒํผ์˜ ์†๋ ฅ์„๊ฐ€์ง€๋Š”์ง€ ๋– ์˜ฌ๋ฆฌ๊ธฐ ํž˜๋“ค๋‹ค. ์ด๋•Œ (3, -3)์„ ์ˆœ์ˆ˜ํ•œ ๋ฐฉํ–ฅ๊ณผ ์ˆœ์ˆ˜ํ•œ ์†๋ ฅ์„ ๋‚˜๋ˆ„์–ด ํ‘œํ˜„ํ•˜๋ฉด ๋ฐฉํ–ฅ๊ณผ ์†๋„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. (3, -3) = ๋ฐฉํ–ฅ * ์†๋ ฅ ๋˜๋Š” ์ด๋™๊ฑฐ๋ฆฌ ๋ฒกํ„ฐ์˜ ์Šค์นผ๋ผ ๊ณฑ์„ ๋ฐฐ์› ๊ณ  ๋•Œ๋ฌธ์— (3, -3)๋Š” (1, -1)์˜ 3๋ฐฐ์— ํ•ด๋‹น๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋ ๊ฒƒ์ด๋‹ค. ํ•˜์ง€๋งŒ (3, -3)์†๋ ฅ ์ž์ฒด๋ฅผ ํ‘œํ˜„ํ•˜์ง€ ๋ชปํ•œ๋‹ค. ์†๋ ฅ์ด 3์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. (1, -1)์˜ ํฌ๊ธฐ(magnitude)๋Š” 1.414… ์ด๊ธฐ๋•Œ๋ฌธ์ด๋‹ค. ‘A์˜ ๋ฐฉํ–ฅ์œผ๋กœ B๋งŒํผ์˜ ์†๋ ฅ’์„ ‘๋ฒกํ„ฐA * ์Šค์นผ๋ผB’๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฒกํ„ฐA๋Š” 1์ด ๋˜์ง€ ์•Š์œผ๋ฉด ์‹ค์ œ ์†๋ ฅ์€ B๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค.

๋”ฐ๋ผ์„œ ๋ฐฉํ–ฅ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ๊ฐ€ 1์ธ ๋ฒกํ„ฐ๋กœ ์ฆ‰ ์ •๊ทœํ™”๋œ ๋ฒกํ„ฐ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ๋‹ค. ๊ฒŒ์ž„์—์„œ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ ์˜ ์œ„์น˜๋ฅผ ํŒŒ์•…ํ•˜๊ณ  ์œ„์น˜์˜ ๋ฒกํ„ฐ ๊ฐ’(๋ฒกํ„ฐ C)์„ ์•Œ๊ณ  ์žˆ์„ ๋•Œ ๊ทธ์— ๋งž๋Š” ๊ฐ’์œผ๋กœ ๊ณ„์† ์•ž์œผ๋กœ ๋‚˜์•„๊ฐ„๋‹ค๋ฉด,

๋ฒกํ„ฐC์˜ ๊ฐ’์— ๋”ฐ๋ผ ์–ด๋Š ๋•Œ๋Š” ๋นจ๋ผ์ง€๊ธฐ๋„ ๋˜๋Š” ๋Š๋ ค์ง€๊ธฐ๋„ ํ•œ๋‹ค. ์ด๋Ÿฐ ์ƒํ™ฉ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ฒกํ„ฐ์˜ ๊ธธ์ด๋ฅผ 1๋กœ ์ •๊ทœํ™”ํ•œ๋‹ค.

  • normailzed ์ ์šฉํ›„ ๋น„๊ต
float speed = 2f;
Vector3 varPose = new Vector3(1,1,1);
//์ด์ „์œ„์น˜
Vector3 prePose;
Vector3 parePose;
float magFloat;

void Update()
{
	prePose = transform.position;
	**transform.Translate(varPose.normalized * speed * Time.deltaTime);** 
	parePose = transform.position - prePose;
	magFloat = parePose.magnitude;
	Debug.Log(magFloat);
}
  • ํ˜„์žฌ ์œ„์น˜์—์„œ ๋ชฉ์ ์ง€๋กœ ํ–ฅํ•˜๋Š” ๋ฐฉํ–ฅ
public GameObject pos1;
public GameObject pos2;
Vector3 objectPos1;
Vector3 objectPos2;
float speed = 10;
Vector3 direction;
float magTarget;
Vector3 nowSpeed;

void Update()
{
	objectPos1 = pos1.transform.position;
	objectPos2 = transform.position;
	magTarget = (objectPos1 - objectPos2).magnitude;
	direction = (objectPos1 - objectPos2).normalized;

	if (magTarget < 10 )
	{
		nowSpeed = direction * speed * Time.deltaTime;
	}
	else
	{
		nowSpeed = new Vector3(0,0,0);
	}

	transform.Translate(nowSpeed);
}

๋ณ€์ˆ˜, ํ•จ์ˆ˜ ๋…ธ๋ž€์ƒ‰ ์ฝ๊ธฐ


  • ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•
**(1) Input.GetKey**
GetKey, GetKeyDown, GetKeyUp

if(Input.GetKey(“Name”))
{ //๋ช…๋ น}
right, left, up, down, space, tab, delete, a, b, c, 1, 2, 3… ๋“ฑ

**(2) Name๋ถ€๋ถ„์— KeyCode**

if(Input.GetKey(KeyCode.UpArrow))
{ //๋ช…๋ น }
Input.GetKeyDown(“space”) == Input.GetKeyDown(KeyCode.Space)
  • ๋งˆ์šฐ์Šค ์ž…๋ ฅ ๋ฐ›๊ธฐ
**(2) Input.GetButton**
GetButton, GetButtonDown, GetButtonUp
if(Input.**GetButtonDown**(“ButtonName”))
{ //๋ช…๋ น }
ButtonName์„ ๋ˆ„๋ฅด๋Š” ๋™์•ˆ true๋กœ ๋ฌด๊ธฐ๋ฅ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฒ„ํŠผ ํŠธ๋ฆฌ๊ฑฐ๋กœ ์‚ฌ์šฉํ• ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
Edit > Project Setting > Input์—์„œ ๋ฏธ๋ฆฌ ์„ค์ •๋œ ButtonName์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ‘Fire1’๋Š” ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ

**(2) Input.GetMouseButton**
GetMouseButton, GetMouseButtonDown, GetMouseButtonUp
if (Input.**GetMouseButtonDown**(0))
{
	print("๋งˆ์šฐ์Šค๋‹ค์šด");
}

**GetMouseButtonDown(0) : ๋งˆ์šฐ์Šค ์™ผ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(1) : ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ
GetMouseButtonDown(2) : ๋งˆ์šฐ์Šค ์ค‘์•™(ํœ ) ๋ฒ„ํŠผ**
  • Rigidbody
Player ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์›€์ง์ž„์„ ์ œ์–ดํ•˜๊ธฐ ์œ„ํ•ด Rigidbody๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
Add Component > Physics > Rigidbody

- ์ค‘๋ ฅ Use Gravity ๋ฅผ ์ฒดํฌํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ฐ‘์œผ๋กœ ๋–จ์–ด์ง„๋‹ค. 
Mass๊ฐ’์— ๋”ฐ๋ผ ๋–จ์–ด์ง€๋Š” ์ค‘๋Ÿ‰ ํ‘œํ˜„ํ•œ๋‹ค. 

-์บก์Š์ฒ˜๋Ÿผ ๋ฐ”๋‹ฅ๋ฉด์ด ๊ณก์„ ์ผ ๊ฒฝ์šฐ ์ค‘๋ ฅ์œผ๋กœ ์˜ํ–ฅ์œผ๋กœ ์“ฐ๋Ÿฌ์งˆ ์ˆ˜ ์žˆ๋‹ค. 
Constaints์—์„œ ์œ„๋กœ ํŠ•๊ฒจ๋‚˜๊ฐ€์ง€ ์•Š๋„๋ก Freeze Position์˜ Y ์ฒดํฌํ•œ๋‹ค.
์ถฉ๋Œ ์ดํ›„ ์›ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐ”๋ผ๋ณด๋„๋ก Freeze Rotation์˜ X์™€ Z๋ฅผ ์ฒดํฌํ•œ๋‹ค.

- ์ถฉ๋Œ์ฒดํฌ๋Š” Collider ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ๋Š” ๋ชจ๋‘ ์ถฉ๋Œ ์ฒดํฌ๋ฅผ ํ•œ๋‹ค. 
๋‹จ, Is Kinematic์ด ์ฒดํฌ๊ฐ€ ๋˜๋ฉด ๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๊ฒŒ ๋œ๋‹ค.

ํ†ตํ†ตํŠ€๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ(๋ฌผ๋ฆฌ ์žฌ์งˆ ๋งŒ๋“ค์–ด์„œ ์ ์šฉํ•˜๊ธฐ)
- Freeze Position์˜ Y ์ฒดํฌ ํ’€๊ธฐ
- Project์ฐฝ์˜ Create > Physic Material ์ถ”๊ฐ€, Bounciness ๊ฐ’์„ 1
- Player์˜ Collider์˜ Material์— ์ถ”๊ฐ€ํ•œ๋‹ค.
  • Rigidbody์— ํž˜์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™
[Rigidbody.AddForce]
public void AddForce(float x, float y, float z, forceMode);
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ํž˜์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํž˜์˜ ๋ฐฉํ–ฅ์„ ๋”ฐ๋ผ ์ผ์ •ํ•œ ํž˜์„ ์ง€์†์ ์œผ๋กœ ๋ถ€์—ฌํ•œ๋‹ค. 
forceMode๋ฅผ ์ง€์ •ํ•˜๋ฉด ๊ฐ€์†(Acceleration), ์ถฉ๊ฒฉ(Impulse), ์†๋„๋ณ€๊ฒฝ(Velocity Change)๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
์—…๋ฐ์ดํŠธ ๋ฌธ์—์„œ ๋ฐฉํ–ฅํ‚ค๋กœ ํž˜์ด ๊ฐ€ํ•ด์ง€๋„๋ก ์ž‘์„ฑํ•˜๊ฒŒ ๋œ๋‹ค
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฐธ์กฐ๋ณ€์ˆ˜๋กœ ์กฐ์ ˆํ•˜๊ธฐ
์ฐธ์กฐ ํƒ€์ž…์œผ๋กœ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ ์กฐ์ข… ๊ฐ€๋Šฅํ•˜๋‹ค. .์ฐธ์กฐ ๋ณ€์ˆ˜๋Š” ์‹ค์ฒด๋Š” ์•„๋‹ˆ์ง€๋งŒ, ์‹ค์ฒด์ฒ˜๋Ÿผ
์ฐธ์กฐ๊ฐ’์„ ์ €์žฅํ•œ๋‹ค. ์ด๋กœ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์Šคํฌ๋ฆฝํŠธ์—์„œ ์ฐธ์กฐ ํƒ€์ž… ๋ณ€์ˆ˜๋กœ ์„ ์–ธ, ์ ‘๊ทผํ•˜์—ฌ, ์ œ์–ด
๊ฐ€๋Šฅํ•˜๋‹ค.
public Rigidbody playerRigidbody;
๋กœ ์„ ์–ธํ•œ ํ›„์—
playerRigidbody.AddForce(0, 500, 0);

 

๐Ÿ’€ ๋ฌธ์ œ

-Rigidbody ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ง์ ‘ ํ• ๋‹นํ•˜์ง€ ์•Š์€ ๋ฐฉ๋ฒ•์€?

: AddFoce()๋Š” ์ ์ง„์ ์œผ๋กœ ์†๋„๊ฐ€ ์ฆ๊ฐ€๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋นจ๋ผ์ง€๋Š”๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค.

: ์ž…๋ ฅ ๊ฐ์ง€ ์ฝ”๋“œ๊ฐ€ ๋ณต์žกํ•˜๋‹ค. ์ฆ‰, IF ๋ฌธ์„ ๋„ˆ๋ฌด ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

 

  • ๋งˆ์šฐ์Šค์™€ ์กฐ์ด์Šคํ‹ฑ
(1) Axis(์ถ•์„ ์ด์šฉ)
Input.GetAxis(“Horizontal”) 
Input.GetAxis(“Vertical”)
Axis์€ ์›€์ง์ด์ง€ ์•Š์„ ๋•Œ๋Š” 0, ์ˆ˜ํ‰์—์„œ ์™ผ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด -1, ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐ€๋ฉด 1 ์ด๋ผ๋Š” ๊ฐ’
์ˆ˜์ง์—์„œ ์œ„๋กœ ์˜ฌ๋ผ๊ฐ€๋ฉด 1, ๋‚ด๋ ค๊ฐ€๋ฉด -1 ์ด๋ผ๋Š” ๊ฐ’
“Horizontal”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์™ผ์ชฝ ๋ฐฉํ–ฅํ‚ค, A | ์–‘์˜ ๋ฐฉํ–ฅ : ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅํ‚ค, D 
“Vertical”
- ์Œ์˜ ๋ฐฉํ–ฅ : ์•„๋ž˜์ชฝ ๋ฐฉํ–ฅํ‚ค, S | ์–‘์˜ ๋ฐฉํ–ฅ : ์œ„์ชฝ ๋ฐฉํ–ฅํ‚ค, W 

(2) ๋งˆ์šฐ์Šค ์™ผ์ชฝ ์˜ค๋ฅธ์ชฝ ์ด๋™ ํ™•์ธ
Input.GetAxis(“Mouse X”)
Input.GetAxis(“Mouse Y”)
  • Rigidbody์˜ ์ด๋™์„ ์ผ์ •ํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ
์ฒ˜์Œ ์›€์ง์ผ ๋•Œ๋Š” ์ž˜ ์›€์ง์ด์ง€๋งŒ, ์ฒœ์ฒœํžˆ ๊ฐ€๋‹ค๊ฐ€ ๋’ค๋กœ ๊ฐˆ์ˆ˜๋ก ๋นจ๋ผ์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์›€์ง์ด๋‹ค ๋ฐฉํ–ฅ ์ „ํ™˜์„
ํ•ด๋ณด๋ฉด ๋ฐ”๋กœ ์ „ํ™˜๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. ๋งˆ์น˜ ๋น™ํŒ์œ„์—์„œ ๋ฐฉํ–ฅ์ „ํ™˜ํ•˜๋“ฏ์ด ๋ฏธ๋„๋Ÿฌ์ ธ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๋˜๋Š” ๋Š๋‚Œ์ผ
๊ฒƒ์ด๋‹ค. ์ด๊ฒƒ์€ ๋ฐ”๋กœ Capsule ์ด๋ผ๋Š” ์˜ค๋ธŒ์ ํŠธ๊ฐ€ Rigidbody๋ผ๋Š” ๋ฌผ๋ฆฌ์  ์†์„ฑ์„ ๊ฐ€์ง€๋ฉด์„œ ํ˜„์žฌ์ƒํƒœ๋ฅผ
์œ ์ง€ํ•˜๋ ค๋Š” **๊ด€์„ฑ์ด ๋ฐ˜์˜๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค**. =>

[Rigidbody.velocity]
public Vector3 velocity;
๋ฆฌ์ง€๋“œ๋ฐ”๋””์— ๋ฒกํ„ฐ๊ฐ’์„ ๋„ฃ์–ด์„œ ํ•ด๋‹น ๋ฐฉํ–ฅ์œผ๋กœ ์›€์ง์ด๋„๋ก ํ•œ๋‹ค. 
์ฆ‰ Rigidbody๋ฅผ ๊ฐ€์ง„ ๋ฌผ์ฒด์— ์ฃผ์–ด์ง„ ์†๋„๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์œผ๋กœ 
์งˆ๋Ÿ‰๊ณผ ๊ด€์„ฑ๋“ค์„ ๋ฌด์‹œํ•˜๊ณ  ์ž…๋ ฅ๋ฐ›์€ ์†๋„๋กœ ๋ฐฉํ–ฅ ์ „ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฉ”์‹œ๋“œ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
private๋กœ ์„ ์–ธํ•œ ์ฐธ์กฐ๋ณ€์ˆ˜๋Š” ์ธ์ŠคํŽ™ํ„ฐ์—์„œ ๋ณผ ์ˆ˜ ์—†๋‹ค. ์Šคํฌ๋ฆฝํŠธ์— GetComponent<>()๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ
๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์•ˆ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ• ๋‹นํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.
public Rigidbody playerRigidbody;
private void Start()
{
	 playerRigidbody = GetComponent<Rigidbody>();
}
  • Character Controller ์ปดํฌ๋„ŒํŠธ
Rigidbody๊ฐ€ ์•„๋‹Œ Add Component > Physics > Character Controller ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋™์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
๋ฆฌ์ง€๋“œ๋ฐ”๋””๋Š” ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋งŽ์ด ์ฐจ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ์œค๋‹ˆํ‹ฐ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์ ์— ์ฐฉ์•ˆํ•ด ์ค‘๋ ฅ์ด๋‚˜ ์ถฉ๋Œ ๋“ฑ์˜
๊ฐ„๋‹จํ•œ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ๋งŒ์„ ํ•„์š”๋กœ ํ•˜๋Š” ์บ๋ฆญํ„ฐ ์ „์šฉ ํด๋ž˜์Šค์ธ character controller๊ฐ€ ์žˆ๋‹ค.
์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด์˜ ์ฝœ๋ผ์ด๋” ์ปดํฌ๋„ŒํŠธ๋Š” ์‚ญ์ œํ•œ๋‹ค.
์ค‘๋ ฅ์ด ์ ์šฉ๋œ ์ด๋™์„ ์œ„ํ•ด ์บ๋ฆญํ„ฐ ์ปจํŠธ๋กค๋Ÿฌ ํด๋ž˜์Šค์˜ Move() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ๋‹ค
  • Trigger(์ด์•Œ๋งŒ๋“ค๊ธฐ)
(1) Sphere - ๋ถ‰์€์ƒ‰ ๋จธํ‹ฐ๋ฆฌ์–ผ ์ ์šฉ
Position = 0, 1.5, -4
Scale = 0.3

(2) Rigidbody ์ถ”๊ฐ€ ํ›„ use Gravity ์ฒดํฌ๋ฅผ ํ•ด์ œ

[Collider]
**Collider ์ปดํฌ๋„ŒํŠธ๋Š” ๋ฌผ๋ฆฌ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์˜ค๋ธŒ์ ํŠธ์˜ ํ˜•ํƒœ๋ฅผ ์ •์˜ํ•œ๋‹ค.** 
์ฝœ๋ผ์ด๋”๋Š” ๋ณด์ด์ง€ ์•Š๋Š” ์š”์†Œ์ด๋ฏ€๋กœ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ฉ”์‹œ์™€ ์ •ํ™•ํžˆ ๋™์ผํ•œ ๋ชจ์–‘์ผ ํ•„์š”๋Š” ์—†์œผ๋ฉฐ, ์‹ค์ œ๋กœ๋Š”
์ž„ํ”Œ๋ ˆ์ด ์‹œ์—๋Š” ๋Œ€๋žต์ ์ธ ๊ทผ์‚ฌ์น˜๋กœ๋„ ํฌ๊ฒŒ ๊ตฌ๋ถ„๋˜์ง€ ์•Š์œผ๋ฉฐ ๋” ํšจ์œจ์ ์ด๋‹ค.
[Collision]
Kinematic(๋ฌผ์ฒด๋ฅผ ํ†ต๊ณผํ•˜๋Š” ์†์„ฑ) ์†์„ฑ์ด ๊บผ์ ธ์žˆ์„ ๋•Œ ๋ฐœ์ƒํ•œ๋‹ค. 
Kinematic์ด ์ผœ์ ธ ์žˆ์œผ๋ฉด ๋‚ด๋ถ€ ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ์•ˆํ•ด์„œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋ฌผ๋ฆฌ ๊ธฐ๋ฐ˜์œผ๋กœ ์ถฉ๋Œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์—ฌ ์ถฉ๋Œํ•  ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ๋‹ค Collider๊ฐ€ ํ•„์š”ํ•˜๊ณ , ๊ทธ ์ค‘ ํ•˜๋‚˜๋Š” Rigidbody๊ฐ€ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

Enter : ์ด์•Œ์ด ๋‚ ์•„์™€ ๋ถ€๋”ช์น˜๋Š” ์ˆœ๊ฐ„ ๋ฐœ์ƒ(OnCollisionEnter)
Stay : ์ถฉ๋Œ ํ›„ ๋ถ™์–ด์žˆ๋Š” ์ƒํ™ฉ์—์„œ ๊ณ„์†์ ์œผ๋กœ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ(OnCollisionStay)
Exit : ๋ถ™์—ฌ์žˆ๋Š” ์ดํ›„ ๋–จ์–ด์ง€๋Š” ์ˆœ๊ฐ„ ์ด๋ฒคํŠธ(OnCollisionExit)

[Trigger]
Collision ์ดํ›„ ์ถฉ๋Œํ–ˆ๋‹ค๋Š”์‹ ํ˜ธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ.
Tirgger๊ฐ€ ์ฒดํฌ ๋˜์–ด ์žˆ๋‹ค๋ฉด ๋ฌผ๋ฆฌ์ ์ธ ํ˜„์ƒ์€ ์—†๊ณ  ์ถฉ๋Œํ–ˆ๋‹ค๊ณ ๋งŒ ์ธ์‹ํ•œ๋‹ค. 
์ถฉ๋Œ ํ•œ์˜ค๋ธŒ์ ํŠธ ๋‘˜ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ ํŠธ๋ฆฌ๊ฑฐ๋ฉด ํŠธ๋ฆฌ๊ฑฐ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
OnTriggerEnter, OnTriggerStay, OnTriggerExit ๊ฐ€ ์žˆ๋‹ค.

**OnCollision : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ์„ ํ†ตํ•ด ์ถฉ๋Œ ์ฒ˜๋ฆฌ, ๊ด€ํ†ต X, ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€ํ•˜๊ฐ€ ๋งŽ์ด ๊ฑธ๋ฆฐ๋‹ค.
OnTrigger : ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ X, ๊ด€ํ†ต ๊ฐ€๋Šฅ, Collision ๋ณด๋‹ค ์—ฐ์‚ฐ์ด ์ ์–ด์„œ ํšจ์œจ์ ์ด๋‹ค.**

  • ํด๋ž˜์Šค์™€ ๊ฐ์ฒด

(1) ํด๋ž˜์Šค์™€ ์˜ค๋ธŒ์ ํŠธ๋Š” ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํ•ต์‹ฌ ๊ฐ์ฒด์ง€ํ–ฅ์€ ์‚ฌ๋žŒ์ด ํ˜„์‹ค ์„ธ์ƒ์„ ๋ณด๋Š” ๋ฐฉ์‹์— ๊ฐ€๊นŒ์šด ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์‚ฌ๋žŒ์€ ํ˜„์‹ค์˜ ์‚ฌ๋ฌผ์„ ‘๋ถ„ํ•ดํ•˜์—ฌ’ ์ƒ๊ฐํ•˜์ง€ ์•Š๊ณ  ์‚ฌ๋ฌผ์„ ‘์˜จ์ „ํ•œ ๋…๋ฆฝ์ฒด’๋กœ ์—ฌ๊ธฐ๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค. ์‚ฌ๋ฌผ์€ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๊ณ , ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ƒ์ƒ์†์˜ ์–ด๋–ค ๊ฒƒ์ผ ์ˆ˜๋„ ์žˆ๋‹ค. ์‚ฌ๋žŒ, ๋™๋ฌผ, ๋ถ€๋ชจ, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๋ชจ๋‘ ์‚ฌ๋ฌผ์ด๋‹ค. ํ•˜์ง€๋งŒ ์ด์ค‘์— ๊ตฌ์ฒด์ ์ด์ง€์•Š๋Š” ๊ฒƒ์ด ์žˆ๋‹ค. ์‚ฌ๋žŒ์€ ๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹Œ ์ถ”์ƒ์ ์ธ ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ด๋ž€๊ตฌ์ฒด์ ์ธ ๊ฐœ๋…์ด ์•„๋‹ˆ๊ณ  ์ถ”์ƒ์  ๊ฐœ๋…์ด๋‹ค. ์ถ”์ƒ์ ์ธ ์‚ฌ๋ฌผ์„ ‘ํด๋ž˜์Šค’, ์ž๋™์ฐจ, ๊ฐ€๊ตฌ, ํ•ธ๋“œํฐ ๋“ฑ ๊ตฌ์ฒด์ ์ธ ๊ฒƒ๋“ค์„ ‘๊ฐ์ฒด’๋ผ๊ณ  ํ•œ๋‹ค.

 

(2) ํด๋ž˜์Šค ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๋Œ€์ƒ์„ ์ถ”์ƒํ™”ํ•˜์—ฌ ๋Œ€์ƒ๊ณผ ๊ด€๋ จ๋œ ๋œ ๋ณ€์ˆ˜ & ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๋Š” ํ‹€์ด๋‹ค.

ํ‹€์€ ๋ˆˆ์— ๋ณด์ด์ง€๋Š” ์•Š์ง€๋งŒ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

ํด๋ž˜์Šค๋Š” ์†์„ฑ๊ณผ ๊ธฐ๋Šฅ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

(3) ๊ฐ์ฒด ๋ฌผ๊ฑด์˜ ์„ค๊ณ„๋„์ธ ํด๋ž˜์Šค์™€ ๋‹ฌ๋ฆฌ ์˜ค๋ธŒ์ ํŠธ๋Š” ์‹ค์ฒด์ด๋‹ค.

‘์‚ฌ๋žŒ’์ด๋ผ๋Š” ํด๋ž˜์Šค๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ํด๋ž˜์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒ์„ฑํ•œ ์˜ค๋ธŒ์ ํŠธ๋Š” ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํด๋ž˜์Šค๋ผ๋Š” ํ‹€๋กœ ์˜ค๋ธŒ์ ํŠธ๋ฅผ์ฐ์–ด๋‚ด๋Š” ๊ฒƒ์„ ์ธ์Šคํ„ด์Šคํ™”ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค. ์ธ์Šคํ„ด์Šคํ™”๋ฅผ์ด์šฉํ•ด ์ƒ์„ฑ๋œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ธ์Šคํ„ด์Šค๋ผ๊ณ ํ•œ๋‹ค.

๋˜ํ•œ, ์ธ์Šคํ„ด์Šคํ•œ ์˜ค๋ธŒ์ ํŠธ๋“ค์€ ์„œ๋กœ ๋…๋ฆฝ์ ์ด๋ฉฐ๊ตฌ๋ณ„ ๊ฐ€๋Šฅํ•œ ์‹ค์ฒด์ด๋‹ค.

  • Instantiate (์ธ์Šคํ„ด์Šค)

(1) ์ธ์Šคํ„ด์Šค ๋ณต์ œ Instantiate() ๋ฉ”์„œ๋“œ๋Š” ์›๋ณธ ์˜ค๋ธŒ์ ํŠธ(Prefab)๋ฅผ ๋ณต์ œํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์ฆ‰, ์ธ์Šคํ„ดํŠธํ™”๋ฅผ ํ•˜์—ฌ ์›๋ณธ์„ ๋ณต์ œํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ Instantiate(์›๋ณธ, ์œ„์น˜, ํšŒ์ „); ๋ณต์ œํ•  ์›๋ณธ, ์ด๋™ํ•  ์œ„์น˜, ์ด๋™ ๋ฐฉํ–ฅ์„ ์„ค์ •

(2) ์ธ์Šคํ„ด์Šค ์‚ญ์ œ Destroy(object, float time); Destroy() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅํ•œ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค. float time ๋งŒํผ ์ง€์—ฐ ํ›„ ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ๋ฅผ ํŒŒ๊ดดํ•œ๋‹ค.

  • Random.Range()

(1) ๋žœ๋คํ•œ ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์œผ๋กœ ํƒ„์•Œ์„ ๊ณ„์† ์ƒ์„ฑ Random.Range() ๋ฉ”์„œ๋“œ๋Š” ์ž…๋ ฅ์œผ๋กœ ์ตœ์†Ÿ๊ฐ’๊ณผ ์ตœ๋Œ“๊ฐ’์„ ์ˆœ์„œ๋Œ€๋กœ ๋ฐ›๊ณ , ๊ทธ ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ˆซ์ž๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. float ์„ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์™€ int ์ž…๋ ฅ๋ฐ›์„ ๋•Œ์˜ ๋™์ž‘์ด ๋‹ค๋ฅด๋‹ค. Random.Range(0, 3) ๋Š” 0, 1, 2 ์ค‘ ํ•˜๋‚˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. Random.Range(0f, 3f)๋Š” 0์—์„œ๋ถ€ํ„ฐ 3f ์‚ฌ์ด์˜ float ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค. 0.5f

  • ์”ฌ์—์„œ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ
**โ— Find(“๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ด๋ฆ„”) - ๊ฐ€์žฅ ์ฒ˜์Œ ๊ฒ€์ƒ‰๋œ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindWithTag(“ํƒœ๊ทธ์ด๋ฆ„”) - ํƒœ๊ทธ๋กœ ๋Œ€์ƒ์„ ์ฐพ์Œ. ์ฒ˜์Œ ์ฐพ์€ ํ•˜๋‚˜์˜ ์˜ค๋ธŒ์ ํŠธ ๋ฐ˜ํ™˜
โ— FindGameObjectsWithTag(“๊ฐ™์€์ด๋ฆ„์˜ ํƒœ๊ทธ”) - ๊ฐ™์€ ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๋ฐฐ์—ด๋กœ ๋ฐ›์Œ
โ— FindObjectOfType(ํƒ€์ž…๋ช…)
โ— FindObjectsOfType(ํƒ€์ž…๋ช…)**

(1) ์”ฌ์—์„œ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ ์ฐพ๊ธฐ FindObjectOfType() ๋ฉ”์„œ๋“œ player๊ฐ€ playerController(์ฝ”๋“œ) ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์žˆ๋‹ค. FindObjectOfType( ) ๋ฉ”์„œ๋“œ๋Š” ๊บพ์‡ <>์— ์–ด๋–ค ํƒ€์ž…์„ ๋ช…์‹œํ•˜๋ฉด ์”ฌ์— ๋ชจ๋“  ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ ํ•ด๋‹น ํƒ€์ž…์˜ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

  • ์˜ค๋ธŒ์ ํŠธ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ

(1) ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ–ฅํ•˜๋„๋ก ํƒ„์•Œ์„ ์ƒ์„ฑ

if(pController.enabled) {
	transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position -
	transform.position),1);
}

Die๋ถ€๋ถ„์— false๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

(2) ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ณ๋‹ค๋ณด๊ฒŒ ๋งŒ๋“ค๊ธฐ transform.LookAt() ๋ฉ”์„œ๋“œ๋Š” ๋‹ค๋ฅธ ๊ฒŒ์ž„ ์˜ค๋ธŒ์ ํŠธ์˜ transform๋ฅผ ๋ฐ›๋Š”๋‹ค. ์ž…๋ ฅ๋ฐ›์€ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์ž์‹ ์˜ transform ํšŒ์ „์„ ๋ณ€๊ฒฝํ•œ๋‹ค.

//Update์—์„œ
bullet.transform.LookAt(target);

 

๐Ÿ’€ ์ตœ์ข… - ๊ฒŒ์ž„๋งค๋‹ˆ์ € ์ œ์ž‘

๊ฒŒ์ž„ ๋งค๋‹ˆ์ €

  1. ๊ฒŒ์ž„์˜ค๋ฒ„๊ฐ€ ๋˜๋ฉด ‘Press R to Restart’ ๋ผ๋Š”๊ธ€์”จ๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.
  2. ๊ฒŒ์ž„์˜ค๋ฒ„ ์‹œ ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘

๋ฉ”์„œ๋“œ

  1. ์”ฌ์„ ๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”using UnityEngine.SceneManagement; </aside>
  • gameManager
(1) Canvas > Text
 Transform Rect์—์„œ
- ์นด๋ฉ”๋ผ ๊ธฐ์ค€์œผ๋กœ ์บ”๋ฒ„์Šค๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณด์ผ ๊ฒƒ์ธ๊ฐ€?
- ์บ”๋ฒ„์Šค ์•ˆ์˜ ํ…์ŠคํŠธ, ๋ฒ„ํŠผ ๋“ค์˜ ์ •๋ ฌ : Alt ํ‚ค๋ฅผ ๋ˆ„๋ฅธ ์ƒํƒœ์—์„œ ๋ฐฐ์น˜
- ์ด ์ƒํƒœ์—์„œ ์‚ฌ์ด์ฆˆ ์กฐ์ ˆ
(2) Text GUI ์ถ”๊ฐ€ํ•˜๊ธฐ
- TimeText : “Time : 0” ์ƒ์กด ์‹œ๊ฐ„ ํ‘œํ˜„
- GameoverText : “Press R to Restart” ํ…์ŠคํŠธ ์ถ”๊ฐ€, ์ œ์ž‘ ํ›„ ๋น„ํ™œ์„ฑํ™”
- RecordText : “Best Record : 0” ํ…์ŠคํŠธ, GameoverText์˜ ์ž์‹์œผ๋กœ ๋งŒ๋“ค๊ธฐ
  • ํ˜„์žฌ๊นŒ์ง€์˜ ์ ์ˆ˜๋ฅผ ๋กœ์ปฌ๋กœ ์ €์žฅํ•˜๊ธฐ
(1) PlayerPref
Player Preference๋ผ๊ณ  ์ฝ์œผ๋ฉฐ ๊ฐ„๋‹จํ•œ ๋ฐฉ์‹์œผ๋กœ ์–ด๋–ค ์ˆ˜์น˜๋ฅผ ๋กœ์ปฌ์— ์ €์žฅํ•˜๊ณ  ๋‚˜์ค‘์— ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฉ”์„œ๋“œ๋ฅผ
์ œ๊ณตํ•œ๋‹ค.

*(2) ์ €์žฅํ•˜๊ธฐ
์‹ค์ˆ˜๊ฐ’์œผ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.SetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.SetFloat(string key, float value);
์ •์ˆ˜๋Š” SetInt(string key, int value);
๋ฌธ์ž์—ด์€ SetString(string key, string value);*

(3) ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ PlayerPref.GetFloat()๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
PlayerPref.GetFloat(string key);
์ •์ˆ˜๋Š” GetInt(string key);
๋ฌธ์ž์—ด์€ GetString(string key);
์ €์žฅ๋œ ๊ฐ’์ด ์—†๋‹ค๋ฉด ๊ธฐ๋ณธ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 0 ๋˜๋Š” ๋นˆ๋ฌธ์ž์—ด

(4) ์ด์ „์— ์ €์žฅํ•œ ๊ฐ’์ด ์žˆ๋Š”์ง€
HasKey(string key);