728x90
VR๊ฐ๋ฐ์ ํ๋ ๋์ค
์ปจํธ๋กค๋ฌ๋ฅผ ์์ง์ด์ง ์๊ณ ๋ ํด๋ฆญํ ์ง์ ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ์ด๋ํด์ฃผ๊ธฐ ์ํ ๋ฐ์์ ์ฐ๊ตฌํ๋ค๊ฐ
์ง ์ฝ๋์์ง๋ง ์ค์ ๋ก ์ฌ์ฉํ์ง๋ ์์๋ค.
<์์ ํ๋ฉด ์ข์ ์ฌํญ>
(1) ํ ์ด๋ธ, ๊ฒ์ํ ๋ฑ์ ์ด๋ ์์น๊ฐ ์ถ๊ฐ๋ ๊ฒฝ์ฐ๋ฅผ ์๊ฐํ์ฌ
๋ฐฐ์ด๋ก ๋ง๋ค์ด์ฃผ๋ฉด ํ์ฅ์ฑ ์ธก๋ฉด์์ ๋์ฑ ์ข์ ๊ฒ ๊ฐ๋ค.
(2) ์
๋ฐ์ดํธ๋ฌธ ์์ if๋ฌธ ์์ ์๋ ๋ก์ง์ ๋ค๋ฅธ ํจ์๋ก ๋ถ๋ฆฌ(๋
๋ฆฝ)์ํค๋ ๊ฒ์ด ์ฅ๊ธฐ์ ์ธ ์ ์ง๋ณด์์ ๋์ฑ ์ข์ ๊ฒ ๊ฐ๋ค.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tempPlayer : MonoBehaviour
{
public GameObject head;//ํ๋ ์ด์ด
public GameObject tablePos;//ํ
์ด๋ธ
public GameObject boardPos;//๊ฒ์ํ
void Update()
{
if(Input.GetMouseButtonDown(0))
{
//ํด๋ฆญํ ์ง์ ์ ์๋ ์ขํ
Vector3 mousePos = Camera.main.ScreenToWorldPoint
(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane));
Vector3 dir = mousePos - Camera.main.transform.position;
dir = dir.normalized;
Debug.DrawRay(Camera.main.transform.position, dir, Color.red);
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, dir, out hit))
{
if(hit.collider.tag=="Table")
{
StartCoroutine(moveCo(tablePos));
}
if (hit.collider.tag == "Board")
{
StartCoroutine(moveCo(boardPos));
}
}
}
}
IEnumerator moveCo(GameObject pos)
{
while (head.transform.position!= pos.transform.position)
{
head.transform.position = Vector3.MoveTowards
(head.transform.position, pos.transform.position, Time.deltaTime * 1.5f);
yield return null;
}
}
}
728x90