void GenerateConeOfView() { Verts = new List <Vector3>(); if (BehaviourRef == null) { BehaviourRef = GetComponentInParent <Assets.Scripts.Brett.GuestNPCBehaviour>(); } var angle = BehaviourRef.AngleOfView; var Distance = BehaviourRef.DistanceOfView; List <Ray> rays = new List <Ray>(); for (float i = -angle; i < angle; i += 2f) { Quaternion spread = Quaternion.AngleAxis(i, transform.up); Vector3 newVec = spread * transform.forward; rays.Add(new Ray(transform.position, newVec)); } Verts.Add(transform.position); foreach (var r in rays) { RaycastHit hit; if (Physics.Raycast(r.origin, r.direction, out hit, Distance)) { Verts.Add(hit.point); } else { Verts.Add(r.origin + (r.direction * Distance)); } } }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { BehaviourRef = GetComponentInParent <Assets.Scripts.Brett.GuestNPCBehaviour>(); Verts = new List <Vector3>(); TriPoints = new List <int>(); SurfaceNormals = new List <Vector3>(); UVs = new List <Vector2>(); InstanceMesh = new Mesh(); GenerateRuntimeSkirt(); }