using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class haptic : MonoBehaviour {
public Transform target;
private float dist;
private string[] tags = {"static_wall", "dynamic_wall"};
GameObject[] taggedWalls = {};
// Use this for initialization
void Start () {
Debug.Log("start haptic");
}
// Update is called once per frame
void Update () {
if(target != null)
{
Debug.DrawLine(transform.position, target.position, Color.yellow);
}
float closestDistSqr = Mathf.Infinity;
Transform closestWall = null;
foreach (string tag in tags)
{
GameObject[] taggedWalls = GameObject.FindGameObjectsWithTag(tag);
foreach(GameObject taggedWall in taggedWalls)
{
Vector3 objectPos = taggedWall.transform.position;
dist = (objectPos - transform.position).sqrMagnitude;
if(dist < closestDistSqr)
{
closestDistSqr = dist;
closestWall = taggedWall.transform;
}
}
target = closestWall;
}
}
}
'XR > Unity3D' 카테고리의 다른 글
Unity 3D에서 object 색상 지정하기 (0) | 2020.11.08 |
---|---|
유니티에서 벡터 사잇각 찾기 (0) | 2019.03.20 |
유니티 - 레이캐스팅 이용하기 (0) | 2018.10.14 |
Unity - Raycast로 앞의 가까운 object 찾기 (0) | 2018.09.30 |
Unity + Oculus Rift (0) | 2018.08.16 |
댓글