Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RaycastTesting : MonoBehaviour
- {
- public int count = 100;
- public float spacing = .1f;
- public LayerMask mask = 0;
- public int missingCasts = 0;
- private void OnDrawGizmos()
- {
- missingCasts = 0;
- Gizmos.matrix = transform.localToWorldMatrix;
- var sx = -spacing * count/2;
- var sy = sx;
- for (int i = 0; i < count; i++)
- {
- float y = sy + i * spacing;
- for (int j = 0; j < count; j++)
- {
- float x = sx + j * spacing;
- RaycastHit hit;
- var p = new Vector3(x, y, 0);
- if (Physics.Raycast(transform.TransformPoint(p) , transform.forward, out hit, 1000, mask))
- {
- Gizmos.color = new Color(0f, 0f, 1f, 0.1f);
- var hitPointLocal = transform.InverseTransformPoint(hit.point);
- Gizmos.DrawLine(p, hitPointLocal);
- }
- else
- {
- Gizmos.color = Color.red;
- Gizmos.DrawRay(new Vector3(x, y, 0), Vector3.forward*100);
- missingCasts++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement