diff --git a/Role/Attack.cs b/Role/Attack.cs index dda676b..e09ff27 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading.Tasks; using UnityEngine; using Debug = UnityEngine.Debug; -using UnityEditor.Animations; using DG.Tweening; public class Attack : MonoBehaviour @@ -18,7 +17,7 @@ public class Attack : MonoBehaviour [Header("攻击CD时间")] public float attackCooldown = 1f; // 攻击冷却时间 private float lastAttackTime = 0f; // 上次攻击的时间 - + [HideInInspector] public List bulltes = new List(); @@ -27,10 +26,10 @@ public class Attack : MonoBehaviour [Header("火焰动画控制器")] public List fireAnis; [Header("子弹起始点")] public Transform BulletStartPos; - [Header("攻击速度")] public float AttackSpeed=1f; + [Header("攻击速度")] public float AttackSpeed = 1f; public Vector2 direction; - [Header("子弹速度加成")]public float roleBulletSpeedAdd=0f; + [Header("子弹速度加成")] public float roleBulletSpeedAdd = 0f; //[Header("子弹长度")] public float scaleFactor; [Header("子弹数量")] public int BulletNumber = 1; [Header("攻击碰撞体")] public CircleCollider2D attackCollider; @@ -41,19 +40,8 @@ public class Attack : MonoBehaviour [Header("攻击范围显示脚本")] public CharacterClick characterClick; public bool isAttack = true; public bool flag = false; - [HideInInspector] public float timer = 0; - //public float AttackScope - //{ - // [DebuggerStepThrough] - // get => attackScope; - // [DebuggerStepThrough] - // set - // { - // attackScope = value; - // GetComponent().radius = attackScope; - // //Debug.Log("攻击半径"+GetComponent().radius); - // } - //} + [HideInInspector] public float timer = 0; + public async void Start() { @@ -75,7 +63,7 @@ public class Attack : MonoBehaviour { - + if (attackCollider) { Collider2D[] colliders = Physics2D.OverlapCircleAll(attackCollider.transform.position, attackCollider.radius); @@ -103,7 +91,7 @@ public class Attack : MonoBehaviour lastAttackTime = Time.time; // 更新上次攻击时间 } - + await Task.Delay(100); // 延迟,避免过于频繁地检测 } @@ -120,15 +108,17 @@ public class Attack : MonoBehaviour if (flag) { timer += Time.deltaTime; - if (timer>AttackStayTime) + if (timer > AttackStayTime) { animator.SetInteger("State", 0); isAttack = true; timer = 0; flag = false; } - } + + //Debug.Log(role.name+"攻击范围的图片大小"+attackRangeSprite.transform.localScale + "color" + attackRangeSprite.color+ "color.a" + attackRangeSprite.color.a + "是否显示"+ attackRangeSprite.enabled); + } public void GetAllColliderInAttackRange(Collider2D[] colliders) @@ -136,7 +126,7 @@ public class Attack : MonoBehaviour foreach (Collider2D collider in colliders) { Role targetRole = collider.GetComponent(); - + if (targetRole && targetRole.camp != role.camp) { role.animationHighlight = 1; @@ -151,12 +141,7 @@ public class Attack : MonoBehaviour else if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) { animator.SetInteger("State", 1); - flag = true; - - - - } lastAttackTime = Time.time; // 更新上次攻击时间 @@ -177,45 +162,6 @@ 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) - { - GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); - 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; - } - else - { - for (int i = 0; i < bulletData.BulletScattering; i++) - { - // 改变子弹方向,根据角色自身的攻击范围来计算 - GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); - BulletGamobj.GetComponent().role = role; - BulletGamobj.GetComponent().attackObj = this; - BulletGamobj.transform.up = direction; - BulletGamobj.transform.position = transform.position; - bulltes.Add(BulletGamobj); - } - } - }*/ - - public void Pointattack() { @@ -225,11 +171,11 @@ public class Attack : MonoBehaviour Debug.LogError("子弹预制体为空"); return; } - - + + for (int i = 0; i < BulletNumber; i++) { - // 改变子弹方向,根据角色自身的攻击范围来计算 + // 改变子弹方向,根据角色自身的攻击范围来计算 GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); BulletGamobj.GetComponent().role = role; BulletGamobj.GetComponent().attackObj = this; @@ -239,7 +185,6 @@ public class Attack : MonoBehaviour BulletGamobj.transform.position = BulletStartPos.position; bulltes.Add(BulletGamobj); } - } @@ -310,7 +255,7 @@ public class Attack : MonoBehaviour // offsetX = -((originalWidth * (role.AttackRange / 2)) / 4f +0.15f); //} offsetX = (newWidth - originalWidth) / 2; - if (offsetX>0) + if (offsetX > 0) { offsetX += 0.15f; } @@ -347,7 +292,7 @@ public class Attack : MonoBehaviour bulltes.Add(bulletGameObj); } - + public void EndFire() { @@ -393,12 +338,7 @@ public class Attack : MonoBehaviour //boxSize.y = role.AttackRange/3; // 设置矩形高度 // 更新矩形碰撞体的尺寸 - attackColliderBox.size = boxSize; - - - - //float originalWidth = attackRangeSprite.bounds.size.x; - //attackRangeSprite.transform.localScale = new Vector3(boxSize.x*1.4f/4, boxSize.y, 1f); + attackColliderBox.size = boxSize; characterClick.OrSizeX = boxSize.x / characterClick.StartSizeX; // * 2f 因为 radius 是半径,图片的尺寸通常是直径 characterClick.OrSizeY = boxSize.y * 2 / characterClick.StartSizeY; float offSetX = (characterClick.StartSizeX - characterClick.OrSizeX) / 2; @@ -409,9 +349,6 @@ public class Attack : MonoBehaviour attackRangeSprite.transform.position = new Vector2(attackRangeSprite.transform.position.x - offSetX, attackRangeSprite.transform.position.y); //characterClick.OrSizeY = 1; Debug.Log("修改图片宽度"); - - - }