我有一个带有敌人的NevMeshSurface。所有敌人都有一个NevMeshAgent。
玩家死亡时,所有敌人都应被摧毁:
public GameObject player;
NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.Warp(transform.position);
}
void Update()
{
if (player.gameObject != null && gameObject.activeSelf)
{
agent.SetDestination(player.transform.position);
}
}
发生这种情况时,我得到了错误:
“ SetDestination”只能在已被激活的活动代理上调用 放在NavMesh上。
这是敌人脚本:
WITH cte
AS (
SELECT c.year_opened
,c.credit_card_id
,count(*) AS transaction_count
FROM credit_cards c
INNER JOIN transactions t ON c.credit_card_id = t.credit_card_id
WHERE t.STATUS = 'completed'
GROUP BY c.year_opened
,c.credit_card_id
)
SELECT cte.year_opened AS 'year opened'
,SUM(CASE
WHEN transaction_count < 10
THEN 1
ELSE 0
END) AS 'Less than 10'
,SUM(CASE
WHEN transaction_count >= 10
AND transaction_count < 30
THEN 1
ELSE 0
END) AS '10 <= transaction count < 30'
,SUM(CASE
WHEN transaction_count >= 30
THEN 1
ELSE 0
END) AS 'Greater than or equal to 30'
FROM CTE
GROUP BY cte.year_opened
生成敌人时会烘焙NevMeshSurface。
效果很好,直到玩家死亡,然后出现错误,我不知道该如何解决。
答案 0 :(得分:0)
看来代理已被破坏,但Update()仍在被调用。查看其余的代码,这似乎不太可能(除非您尚未发布的代码中有些奇怪的东西)。我将修改Update方法以调试实际上出了什么问题:
void Update()
{
if (player.gameObject != null && gameObject.activeSelf)
{
print("Is agent null: " + (agent == null));
agent.SetDestination(player.transform.position);
}
}
答案 1 :(得分:0)
我今天找到了解决方案:
我在消灭敌人后0.5秒改变了玩家的位置,现在一切正常!