August 2018
Beginner
334 pages
10h 19m
English
We need to create a function for checking whether a position is in the same room as the others:
public bool IsInSameRoom(Vector3 from, Vector3 location, string tagWall = "Wall")
{
RaycastHit[] hits;
Vector3 direction = location - from;
float rayLength = direction.magnitude;
direction.Normalize();
Ray ray = new Ray(from, direction);
hits = Physics.RaycastAll(ray, rayLength);
foreach (RaycastHit h in hits)
{
string tagObj = h.collider.gameObject.tag;
if (tagObj.Equals(tagWall))
return false;
}
return true;
}
Read now
Unlock full access