Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class Actor:MonoBehaviour {
- public List<Transform> losMarkers = new List<Transform>();
- public bool HasLineOfSightToActor(Actor actor, Vector3 fromPos, float minScore) {
- if (!actor) return false;
- float score = 0.0f;
- float totalTests = 1.0f+actor.losMarkers.Count;
- if (TestLineOfSight(actor, fromPos, actor.transform.position)) {
- score++;
- }
- for (int i = 0; i < actor.losMarkers.Count; i++) {
- if (TestLineOfSight(actor, fromPos, actor.losMarkers[i].position)) {
- score++;
- }
- }
- score /= totalTests;
- if (score >= minScore) {
- return true;
- }
- return false;
- }
- public bool TestLineOfSight(Actor actor, Vector3 fromPos,Vector3 pos) {
- RaycastHit hit;
- if (Physics.Linecast(fromPos,pos,out hit)) {
- if (hit.collider.gameObject != actor.gameObject) {
- Debug.DrawLine(fromPos,pos,new Color(1,0,0,1));
- return false;
- }
- }
- Debug.DrawLine(fromPos,pos,new Color(0,1,0,1));
- return true;
- }
- }
Add Comment
Please, Sign In to add comment