这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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;
}
}