[Unity] ๋งˆ์šฐ์Šค๋กœ ์˜ค๋ธŒ์ ํŠธ ํด๋ฆญ ์‹œ ์ธ์‹ํ•˜๊ธฐ
๐ŸŽฎ Unity

[Unity] ๋งˆ์šฐ์Šค๋กœ ์˜ค๋ธŒ์ ํŠธ ํด๋ฆญ ์‹œ ์ธ์‹ํ•˜๊ธฐ

๋งˆ์šฐ์Šค๋กœ ์บ๋ฆญํ„ฐ๋ฅผ ํด๋ฆญํ•˜๋ฉด ์บ๋ฆญํ„ฐ๋ฅผ ์ธ์‹ํ•˜๊ณ  ํŠน์ • ๋Œ€์‚ฌ๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ์—ˆ๋˜ ๋‚˜..

 

 

 

๋งํ’์„ ์„ ๋ณด๋ฉด ์ฃผ๋ฏผ์„ ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ•ด ๋ง์„ ๊ฑธ๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

 

์ฒœ์‚ฌ์ฃผ๋ฏผ, ์•…๋งˆ์ฃผ๋ฏผ์„ ๊ฐ๊ฐ ํด๋ฆญํ•˜๋ฉด ๋‹ค๋ฅธ ๋งํ’์„ ์ด ๋‚˜ํƒ€๋‚œ๋‹ค.

 

์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ๋งˆ์šฐ์Šค๋กœ ๋ฌผ์ฒด๋ฅผ ํด๋ฆญํ•˜๊ณ , ์ด๋ฅผ ์ธ์‹ํ•ด ๋ฌผ์ฒด๋ฅผ ํŒ๋ณ„ํ•˜์—ฌ ๋ช…๋ น์„ ์ค„ ์ˆ˜ ์žˆ์„๊นŒ?

 

๋ฐ”๋กœ RaycastHit์™€ tag๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

Raycast๋ž€ Raycast ์Šคํฌ๋ฆฝํŒ…์„ ๊ฐ€์ง„ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ์˜ ์›์ ์—์„œ ๋‚ด๊ฐ€ ์„ค์ •ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ
Ray(๋ˆˆ์— ๋ณด์ด์ง€ ์•Š๋Š” ๊ด‘์„ )๋ฅผ ๋‚ ๋ ค ํŠน์ • ๊ฑฐ๋ฆฌ ์ด๋‚ด์— ๋ฌผ์ฒด์˜ ์ถฉ๋Œ๊ฐ์ง€๋ฅผ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.

 

์ด ๋•Œ Ray๋ฅผ ๋งˆ์šฐ์Šค์˜ ํฌ์ง€์…˜์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญ ํ›„ ๋ฌผ์ฒด ๊ฐ์ง€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

            // ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ•ด์„œ ์ธ์‹ ํ›„ ๋Œ€ํ™”
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log(hit.transform.gameObject);

                if (hit.transform.gameObject.tag == "Devil") // ์•…๋งˆ๋งŒ๋‘ ํด๋ฆญ ์‹œ
                {
                    talkPanel.SetActive(true);
                    nametag.SetActive(true);
                    npcName.text = "์•…๋งˆ๋งŒ๋‘";
                    talkObjectText.text = "์ฝฐ์•„์•„์•„์•… ๊บผ์ ธ";
                    devil_clickCount++;
                    Debug.Log(devil_clickCount);
                    mouseClick = false;
                }

                else if (hit.transform.gameObject.tag == "Angel")
                {  
                    talkPanel.SetActive(true);
                    nametag.SetActive(true);
                    npcName.text = "์ฒœ์‚ฌ๋งŒ๋‘";

                    if (npc_clickCount == 0) // ์ฒœ์‚ฌ๋งŒ๋‘ ํด๋ฆญ ์‹œ
                    {
                        talkObjectText.text = "์šฉ๊ฐํ•œ ๋ชจํ—˜๊ฐ€๋‹˜.. ์ €ํฌ๋ฅผ ๊ตฌํ•˜๋Ÿฌ ์™€์ฃผ์…จ๊ตฐ์š”!";
                        npc_clickCount++;
                    }
                    mouseClick = false;

                }