diff --git a/Role/Attack.cs b/Role/Attack.cs index dfadf72..0d28e6b 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; using UnityEngine; using Debug = UnityEngine.Debug; @@ -54,14 +55,18 @@ public class Attack : MonoBehaviour Role targetRole = collider.GetComponent(); if (targetRole && targetRole.camp != role.camp) { - Debug.Log("检测到碰撞器: " + collider.name); + role.animationHighlight = 1; attack(targetRole); lastAttackTime = Time.time; // 更新上次攻击时间 break; // 只攻击一个目标 } + else + { + role.animationHighlight = 0; + } } + } - // Debug.Log("=====--"); await Task.Delay(100); // 延迟,避免过于频繁地检测 } else @@ -73,12 +78,15 @@ public class Attack : MonoBehaviour public void attack(Role targetRole) { + if (bulletPrefab == null) { Debug.LogError("子弹预制体为空"); return; } + + Vector2 direction = (targetRole.transform.position - transform.position).normalized; if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) @@ -103,7 +111,6 @@ public class Attack : MonoBehaviour BulletGamobj.transform.position = transform.position; bulltes.Add(BulletGamobj); } - } } diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 52e8f93..4dad3f8 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -110,7 +110,7 @@ public class Bullet : MonoBehaviour if (myBulletType!=BulletType.Spraying) { attackObj.bulltes.Remove(this.gameObject); - Debug.Log("ѳɹƳǰб" + attackObj.bulltes.Count); + //Debug.Log("ѳɹƳǰб" + attackObj.bulltes.Count); Destroy(this.gameObject); } } @@ -119,14 +119,14 @@ public class Bullet : MonoBehaviour private void OnTriggerExit2D(Collider2D collision) { - Debug.Log("ⷶΧ"); + //Debug.Log("ⷶΧ"); Role Crole = collision.gameObject.GetComponent(); if (Crole) { if (Crole.camp != role.camp) { attackObj.bulltes.Remove(this.gameObject); - Debug.Log("ѳɹƳǰб" + attackObj.bulltes.Count); + //Debug.Log("ѳɹƳǰб" + attackObj.bulltes.Count); Destroy(this.gameObject); } } diff --git a/Role/Role.cs b/Role/Role.cs index b9a777f..673beaf 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -43,6 +43,7 @@ public class Role : Fun [Header("hp")] public Image Hpfiil; [Header("Ѫ")] public GameObject HpTextPrefab; [Header("ԼĻ")]public Canvas _Canvas; + public float Hp { get => hp; @@ -123,14 +124,10 @@ public class Role : Fun if (Application.isPlaying) { - - - if (attackClass) { attackClass.role = this; } - UpdateBuff(); //Navigation.MoveToNextWaypoint(gameObject); } @@ -167,7 +164,6 @@ public class Role : Fun return; }; OnAnimationStart?.Invoke(animationHighlight); - CurrentIndex = 0; var lsanimationHighlight = animationHighlight; foreach (Sprite sprite in LightSprite) { @@ -187,8 +183,6 @@ public class Role : Fun OnAnimationIng?.Invoke(animationHighlight); await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval); } - - CurrentIndex++; } else { @@ -200,6 +194,7 @@ public class Role : Fun if (lsanimationHighlight == dieIndex) { + SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // յǰ˵ ResetAllStatus(); } @@ -294,13 +289,7 @@ public class Role : Fun mycollider.enabled = true; // ײ } - - // Ҫõ״̬ } - - - - - + }