死亡计数修改

This commit is contained in:
GL 2024-12-27 22:58:44 +08:00
parent 0d58228599
commit c04f3f2ed9
3 changed files with 37 additions and 37 deletions

View File

@ -366,42 +366,21 @@ private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)//
} }
else if(attackColliderBox) else if(attackColliderBox)
{ {
if (attackColliderBox == null || attackRangeSprite == null)
{
Debug.LogError("Attack Collider or Attack Range Sprite is missing!");
return; // 如果没有找到攻击碰撞体或攻击范围图片,提前返回
}
Vector2 boxSize = attackColliderBox.size; Vector2 boxSize = attackColliderBox.size;
// 假设攻击范围决定了矩形的长宽比 // 假设攻击范围决定了矩形的长宽比
boxSize.x = role.AttackRange * 2f; // 设置矩形宽度 // attackRange * 2 可以增加攻击范围的矩形尺寸,调整比例或常数以适应你的需要
//boxSize.y = role.AttackRange / 3; // 设置矩形高度(如果需要,可以调整比例) boxSize.x = role.AttackRange * 2f+2; // 设置矩形宽度
//boxSize.y = role.AttackRange/3; // 设置矩形高度
// 更新矩形碰撞体的尺寸 // 更新矩形碰撞体的尺寸
attackColliderBox.size = boxSize; attackColliderBox.size = boxSize;
// 确保 attackRangeSprite.bounds.size 不为零
if (attackRangeSprite.bounds.size.x == 0 || attackRangeSprite.bounds.size.y == 0)
{
Debug.LogError("Attack Range Sprite bounds size is invalid.");
return;
}
// 调整攻击范围图片的缩放,使其与碰撞体的大小一致
float scaleX = boxSize.x / attackRangeSprite.bounds.size.x * 3 * 0.75f;
float scaleY = boxSize.y / attackRangeSprite.bounds.size.y * 2;
// 确保计算结果不是无效值(如 Infinity 或 NaN //float originalWidth = attackRangeSprite.bounds.size.x;
scaleX = Mathf.Clamp(scaleX, 0.1f, 10f); // 设置合理的范围,防止缩放过大或过小 //attackRangeSprite.transform.localScale = new Vector3(boxSize.x*1.4f/4, boxSize.y, 1f);
scaleY = Mathf.Clamp(scaleY, 0.1f, 10f); Debug.Log("修改图片宽度");
// 保留两位小数
scaleX = Mathf.Round(scaleX * 100f) / 100f;
scaleY = Mathf.Round(scaleY * 100f) / 100f;
// 设置图片的缩放
attackRangeSprite.transform.localScale = new Vector3(scaleX, scaleY, 1f);
} }

View File

@ -80,11 +80,16 @@ public class Fun : Base
finalDamage = 0; finalDamage = 0;
} }
targetAudience.Hp -= finalDamage; targetAudience.Hp -= finalDamage;
if (targetAudience.Hp<=0) if (targetAudience.Hp<=0&&targetAudience.HaveDieTime==1)
{ {
UserObj.killNum++; UserObj.killNum++;
Debug.Log(UserObj.name+"击杀数量"+ UserObj.killNum); Debug.Log(UserObj.name+"击杀数量"+ UserObj.killNum);
} }
targetAudience.HurtDirectin = direction; targetAudience.HurtDirectin = direction;

View File

@ -82,13 +82,13 @@ public class Role : Fun
get => hp; get => hp;
set set
{ {
//if (hp<0)
//{
// return;
//}
float temp = hp; float temp = hp;
hp = value; hp = value;
// ¸üÐÂѪÌõÏÔʾ // ¸üÐÂѪÌõÏÔʾ
if (Hpfiil != null) if (Hpfiil != null)
{ {
@ -188,6 +188,10 @@ public class Role : Fun
/// </summary> /// </summary>
public List<Action<Role>> PlayerBuff=new List<Action<Role>>(); public List<Action<Role>> PlayerBuff=new List<Action<Role>>();
public bool IsDead = false;
public int HaveDieTime = 0;
public virtual async void Start() public virtual async void Start()
{ {
@ -291,9 +295,10 @@ public class Role : Fun
if (lsanimationHighlight == dieIndex) if (lsanimationHighlight == dieIndex)
{ {
SpawnPool.intance.DeadNumber += 1;
SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中 Destroy(gameObject);
ResetAllStatus(); // SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // »ØÊÕµ±Ç°µÐÈ˵½³ØÖÐ
// ResetAllStatus();
} }
if (lsanimationHighlight == hitIndex) if (lsanimationHighlight == hitIndex)
@ -310,11 +315,20 @@ public class Role : Fun
/// </summary> /// </summary>
public virtual void die() public virtual void die()
{ {
if (Application.isPlaying) if (Application.isPlaying)
{ {
animationHighlight = dieIndex; animationHighlight = dieIndex;
Navigation.PauseAnimation(); Navigation.PauseAnimation();
//mycollider.enabled = false;
if (!IsDead)
{
UIContorl.instance.Killnumber++;
//Destroy(gameObject);
IsDead = true;
}
HaveDieTime++;
Debug.Log("die"); Debug.Log("die");
} }
@ -378,6 +392,8 @@ public class Role : Fun
/// </summary> /// </summary>
public void ResetAllStatus() public void ResetAllStatus()
{ {
IsDead = false;
// ÖØÖÃѪÁ¿ // ÖØÖÃѪÁ¿
Hp = 100f; Hp = 100f;