怪物追玩家

怪物跟踪算法

1
2
3
4
5
6
7
8
9
10
11
12
void Update()
{
if (player != null)
{

// 计算怪物和玩家之间的方向向量
Vector2 向量= (玩家.position - transform.position).normalized;
// 移动怪物
transform.Translate(direction * 速度* Time.deltaTime);

}
}