This commit is contained in:
liuliang 2024-12-30 17:51:13 +08:00
parent cfcbd6c168
commit b41d02098c

View File

@ -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
@ -27,10 +26,10 @@ public class Attack : MonoBehaviour
[Header("火焰动画控制器")] public List<Animator> 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<CircleCollider2D>().radius = attackScope;
// //Debug.Log("攻击半径"+GetComponent<CircleCollider2D>().radius);
// }
//}
[HideInInspector] public float timer = 0;
public async void Start()
{
@ -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)
@ -151,12 +141,7 @@ public class Attack : MonoBehaviour
else if (bulletPrefab.GetComponent<Bullet>().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<Bullet>().myBulletType == BulletType.Spraying)
{
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
BulletGamobj.GetComponent<Bullet>().role = role;
BulletGamobj.GetComponent<Bullet>().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<Bullet>().role = role;
BulletGamobj.GetComponent<Bullet>().attackObj = this;
BulletGamobj.transform.up = direction;
BulletGamobj.transform.position = transform.position;
bulltes.Add(BulletGamobj);
}
}
}*/
public void Pointattack()
{
@ -229,7 +175,7 @@ public class Attack : MonoBehaviour
for (int i = 0; i < BulletNumber; i++)
{
// 改变子弹方向,根据角色自身的攻击范围来计算
// 改变子弹方向,根据角色自身的攻击范围来计算
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
BulletGamobj.GetComponent<Bullet>().role = role;
BulletGamobj.GetComponent<Bullet>().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;
}
@ -394,11 +339,6 @@ public class Attack : MonoBehaviour
// 更新矩形碰撞体的尺寸
attackColliderBox.size = boxSize;
//float originalWidth = attackRangeSprite.bounds.size.x;
//attackRangeSprite.transform.localScale = new Vector3(boxSize.x*1.4f/4, boxSize.y, 1f);
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("修改图片宽度");
}