-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreatureController.cs
42 lines (31 loc) · 1.05 KB
/
CreatureController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
///AMG March 19th, 2017
///This is used to check distance of creatures / NPC / Allies and others
///if within distance, activate objects, otherwise they remain inactive to optimize game
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class CreatureController : MonoBehaviour {
public float sightDistance = 70;
public List<GameObject> creatures = new List<GameObject>();
public void CheckCreature (GameController gameController, GameObject creature)
{
bool withinSight = false;
foreach (GameObject player in gameController.players)
{
// Debug.Log(player);
float distancePlayer = Vector3.Distance(player.transform.position, creature.transform.position);
if (distancePlayer <= 70)
{
withinSight = true;
}
}
if (withinSight == true)
{
creature.SetActive(true);
}
else
{
creature.SetActive(false);
}
}
}