-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAggroArea.cs
More file actions
35 lines (32 loc) · 1.29 KB
/
AggroArea.cs
File metadata and controls
35 lines (32 loc) · 1.29 KB
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
// Catches the Aggro Sphere's OnTrigger functions and forwards them to the
// Entity. Make sure that the aggro area's layer is IgnoreRaycast, so that
// clicking on the area won't select the entity.
//
// Note that a player's collider might be on the pelvis for animation reasons,
// so we need to use GetComponentInParent to find the Entity script.
//
// IMPORTANT: Monster.OnTriggerEnter would catch it too. But this way we don't
// need to add OnTriggerEnter code to all the entity types that need
// an aggro area. We can just reuse it.
// (adding it to Entity.OnTriggerEnter would be strange too, because
// not all entity types should react to OnTriggerEnter with aggro!)
using UnityEngine;
namespace uMMORPG
{
[RequireComponent(typeof(SphereCollider))] // aggro area trigger
public class AggroArea : MonoBehaviour
{
public Entity owner; // set in the inspector
// same as OnTriggerStay
void OnTriggerEnter(Collider co)
{
Entity entity = co.GetComponentInParent<Entity>();
if (entity) owner.OnAggro(entity);
}
void OnTriggerStay(Collider co)
{
Entity entity = co.GetComponentInParent<Entity>();
if (entity) owner.OnAggro(entity);
}
}
}