From 2e5e8ae1d1fd0b501719f03ad233b124a7926fd5 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Tue, 17 Dec 2024 17:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BB=E5=87=BB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Attack.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++++---- Role/Bullet.cs | 9 +++++-- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/Role/Attack.cs b/Role/Attack.cs index 0d28e6b..25e7cf9 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -14,12 +14,14 @@ public class Attack : MonoBehaviour [Header("攻击范围")] public float attackScope; [Header("攻击类型")] public DamageType damageTyp = DamageType.noAttributeDamage; - [Header("攻击冷却时间(秒)")] public float attackCooldown = 1f; // 攻击冷却时间 + [Header("攻击持续时间")] public float attackCooldown = 1f; // 攻击冷却时间 private float lastAttackTime = 0f; // 上次攻击的时间 [HideInInspector] public List bulltes = new List(); + [Header("角色动画控制器")] public Animator animator; + [Header("火焰动画控制器")] public Animator fireAni; public float AttackScope { [DebuggerStepThrough] @@ -56,13 +58,31 @@ public class Attack : MonoBehaviour if (targetRole && targetRole.camp != role.camp) { role.animationHighlight = 1; - attack(targetRole); - lastAttackTime = Time.time; // 更新上次攻击时间 + if (animator!=null) + { + animator.SetInteger("State", 1); + lastAttackTime = Time.time; // 更新上次攻击时间 + } + else + { + attack(targetRole); + lastAttackTime = Time.time; // 更新上次攻击时间 + } + break; // 只攻击一个目标 } else { - role.animationHighlight = 0; + + if (animator != null) + { + animator.SetInteger("State", 0); + } + else + { + role.animationHighlight = 0; + } + } } @@ -95,7 +115,7 @@ public class Attack : MonoBehaviour BulletGamobj.GetComponent().role = role; BulletGamobj.GetComponent().attackObj = this; // BulletGamobj.transform.up = direction; - BulletGamobj.transform.position = transform.position; + BulletGamobj.transform.position =new Vector2(transform.position.x+0.15f, transform.position.y+0.2f); bulltes.Add(BulletGamobj); return; } @@ -114,6 +134,42 @@ public class Attack : MonoBehaviour } } + + public void Fireattack() + { + + if (bulletPrefab == null) + { + Debug.LogError("子弹预制体为空"); + return; + } + + + + + if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) + { + GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); + fireAni = BulletGamobj.GetComponentInChildren(); + BulletGamobj.GetComponent().role = role; + BulletGamobj.GetComponent().attackObj = this; + + // BulletGamobj.transform.up = direction; + BulletGamobj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f); + bulltes.Add(BulletGamobj); + return; + } + + } + + public void EndFire() + { + fireAni.SetInteger("State", 1); + Debug.Log("停止火焰"); + + } + + private void OnDisable() { bulltes.Clear(); diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 4dad3f8..748b30c 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -125,9 +125,14 @@ public class Bullet : MonoBehaviour { if (Crole.camp != role.camp) { - attackObj.bulltes.Remove(this.gameObject); + //Debug.Log("ѳɹƳǰб" + attackObj.bulltes.Count); - Destroy(this.gameObject); + if (myBulletType != BulletType.Spraying) + { + attackObj.bulltes.Remove(this.gameObject); + Destroy(this.gameObject); + } + } } }