您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
39 行
937 B
39 行
937 B
using System;
|
|
using UnityEngine;
|
|
|
|
public class Critter : MonoBehaviour
|
|
{
|
|
[HideInInspector] public bool isPlayerInAlertZone;
|
|
[HideInInspector] public bool isPlayerInAttackZone;
|
|
public Damageable currentTarget; //The StateMachine evaluates its health when needed
|
|
|
|
public void OnAlertTriggerChange(bool entered, GameObject who)
|
|
{
|
|
isPlayerInAlertZone = entered;
|
|
|
|
if (entered && who.TryGetComponent(out Damageable d))
|
|
{
|
|
currentTarget = d;
|
|
currentTarget.OnDie += OnTargetDead;
|
|
}
|
|
else
|
|
{
|
|
currentTarget = null;
|
|
}
|
|
}
|
|
|
|
public void OnAttackTriggerChange(bool entered, GameObject who)
|
|
{
|
|
isPlayerInAttackZone = entered;
|
|
|
|
//No need to set the target. If we did, we would get currentTarget to null even if
|
|
//a target exited the Attack zone (inner) but stayed in the Alert zone (outer).
|
|
}
|
|
|
|
private void OnTargetDead()
|
|
{
|
|
currentTarget = null;
|
|
isPlayerInAlertZone = false;
|
|
isPlayerInAttackZone = false;
|
|
}
|
|
}
|