- Home /
Change the Layer of Colliders in specific portion of Viewport
Greetings. I am attempting to make it so that all objects in the bottom right of the viewport are placed on the "Ignore Raycast" layer. However, I have had difficulty finding success in this endeavor; my code is as follows:
Camera cam = (Camera)FindObjectOfType(typeof(Camera));
Vector3 gtPos = GameObject.FindGameObjectWithTag ("GT").transform.position;
Vector3 gtScreenPos = cam.WorldToViewportPoint(gtPos);
Vector3 pos = cam.ViewportToWorldPoint(new Vector3(Screen.width,0,gtScreenPos.z));
nearbyColliders = Physics.OverlapSphere(pos,10);
foreach (Collider c in nearbyColliders)
{
c.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast");
}
I am unsure as to what I might be doing wrong. Any help would be greatly appreciated.
Comment