Guest User

Untitled

a guest
Dec 12th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. public class Actor:MonoBehaviour {
  7.     public List<Transform> losMarkers = new List<Transform>();
  8.    
  9.     public bool HasLineOfSightToActor(Actor actor, Vector3 fromPos, float minScore) {
  10.         if (!actor) return false;
  11.         float score = 0.0f;
  12.         float totalTests = 1.0f+actor.losMarkers.Count;
  13.        
  14.         if (TestLineOfSight(actor, fromPos, actor.transform.position)) {
  15.             score++;
  16.         }
  17.        
  18.         for (int i = 0; i < actor.losMarkers.Count; i++) {
  19.             if (TestLineOfSight(actor, fromPos, actor.losMarkers[i].position)) {
  20.                 score++;
  21.             }
  22.         }
  23.        
  24.         score /= totalTests;
  25.        
  26.         if (score >= minScore) {
  27.             return true;
  28.         }
  29.         return false;
  30.     }
  31.    
  32.     public bool TestLineOfSight(Actor actor, Vector3 fromPos,Vector3 pos) {
  33.         RaycastHit hit;
  34.         if (Physics.Linecast(fromPos,pos,out hit)) {
  35.             if (hit.collider.gameObject != actor.gameObject) {
  36.                 Debug.DrawLine(fromPos,pos,new Color(1,0,0,1));
  37.                 return false;
  38.             }
  39.         }
  40.         Debug.DrawLine(fromPos,pos,new Color(0,1,0,1));
  41.         return true;
  42.     }
  43. }
Add Comment
Please, Sign In to add comment