(client) feat:实现子弹的生成
This commit is contained in:
@ -134,7 +134,7 @@ namespace Entity
|
||||
// 协程引用
|
||||
private Coroutine attackCoroutine;
|
||||
|
||||
protected PawnDef entityDef;
|
||||
protected EntityDef entityDef;
|
||||
|
||||
|
||||
public float hitBarUIShowTime = 5;
|
||||
@ -144,14 +144,14 @@ namespace Entity
|
||||
/// <summary>
|
||||
/// 初始化实体的基本属性和行为树。
|
||||
/// </summary>
|
||||
/// <param name="pawnDef">实体的定义数据。</param>
|
||||
public virtual void Init(PawnDef pawnDef)
|
||||
/// <param name="entityDef">实体的定义数据。</param>
|
||||
public virtual void Init(EntityDef entityDef)
|
||||
{
|
||||
attributes = pawnDef.attributes.Clone();
|
||||
aiTree = Utils.BehaviorTree.ConvertToAIBase(pawnDef.behaviorTree);
|
||||
affiliation = pawnDef.affiliation;
|
||||
InitBody(pawnDef.drawingOrder);
|
||||
entityDef = pawnDef;
|
||||
attributes = entityDef.attributes.Clone();
|
||||
aiTree = Utils.BehaviorTree.ConvertToAIBase(entityDef.behaviorTree);
|
||||
affiliation = entityDef.affiliation;
|
||||
InitBody(entityDef.drawingOrder);
|
||||
this.entityDef = entityDef;
|
||||
|
||||
HideHealthBar();
|
||||
}
|
||||
@ -288,9 +288,18 @@ namespace Entity
|
||||
/// <param name="orientation">新的朝向。</param>
|
||||
public virtual void SetOrientation(Orientation orientation)
|
||||
{
|
||||
bodyNodes[currentOrientation]?.SetActive(false);
|
||||
// 禁用当前朝向的节点
|
||||
if (bodyNodes.TryGetValue(currentOrientation, out var currentNode))
|
||||
{
|
||||
currentNode.SetActive(false);
|
||||
}
|
||||
// 设置新的朝向
|
||||
currentOrientation = orientation;
|
||||
bodyNodes[orientation]?.SetActive(true);
|
||||
// 激活新朝向的节点
|
||||
if (bodyNodes.TryGetValue(orientation, out var newNode))
|
||||
{
|
||||
newNode.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -475,20 +484,13 @@ namespace Entity
|
||||
|
||||
public void DetectAndAttackEnemies()
|
||||
{
|
||||
const int attackRange = 3;
|
||||
var attackCount = 3;
|
||||
|
||||
// 获取攻击范围内的所有碰撞体,使用LayerMask过滤掉非敌人
|
||||
var attackCount = attributes.attackTargetCount;
|
||||
// 获取攻击范围内的所有碰撞体
|
||||
var hits = Physics2D.OverlapCircleAll(
|
||||
transform.position,
|
||||
attackRange,
|
||||
attributes.attackRange,
|
||||
LayerMask.GetMask("Entity"));
|
||||
|
||||
// 或者使用标签过滤(如果敌人有特定标签)
|
||||
// Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, attackRange);
|
||||
|
||||
Debug.Log($"Found {hits.Length} potential targets in attack range");
|
||||
|
||||
foreach (var hit in hits)
|
||||
{
|
||||
if (attackCount <= 0) break;
|
||||
|
Reference in New Issue
Block a user