From 2d4dd3e1c9e746dc5568626b91fdc9cb45cb56cc Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Fri, 3 Jan 2025 18:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B0=B4=E9=B2=A8=E9=B1=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Attack.cs | 45 +++++++++++++++ Role/Bullet.cs | 36 ++++++++++-- Role/Role.cs | 17 ++++-- Role/SmallBullet.cs | 120 +++++++++++++++++++++++++++++++++++++++ Role/SmallBullet.cs.meta | 11 ++++ 5 files changed, 220 insertions(+), 9 deletions(-) create mode 100644 Role/SmallBullet.cs create mode 100644 Role/SmallBullet.cs.meta diff --git a/Role/Attack.cs b/Role/Attack.cs index bf18bd8..ac669bc 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -38,6 +38,8 @@ public class Attack : MonoBehaviour [Header("攻击持续时间")] public float AttackStayTime;// [Header("攻击目标")] public GameObject Target; [Header("攻击范围显示脚本")] public CharacterClick characterClick; + [Header("攻击随机角度范围")] public float Angle=30; + [Header("子弹分裂个数")] public int splitNum = 2; public bool isAttack = true; public bool flag = false; [HideInInspector] public float timer = 0; @@ -355,4 +357,47 @@ public class Attack : MonoBehaviour } + + public void RandPointattack()//在一个角度随机发射子弹 仓鼠攻击方式 + { + + if (bulletPrefab == null) + { + 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; + BulletGamobj.GetComponent().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd); + BulletGamobj.GetComponent().Target = Target; + + // 计算一个随机偏移角度,在-15度到+15度之间 + float randomAngle = Random.Range(-Angle/2, Angle/2); + Debug.Log("土角度"+Angle); + // 将原始方向转换为角度 + float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; + + // 加上随机偏移角度 + angle += randomAngle; + + // 将角度转换回方向 + direction = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)); + + // 设置子弹的方向 + BulletGamobj.transform.up = direction; + + // 设置子弹的起始位置 + BulletGamobj.transform.position = BulletStartPos.position; + + // 将子弹添加到列表中 + bulltes.Add(BulletGamobj); + } + + } } diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 498b299..d045d14 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -80,14 +80,17 @@ public class Bullet : MonoBehaviour [Header("ӵ")] public BulletAttributes bulletAttributes; [Header("")] public BulletMoveType bulletMoveType; [Header("ӵ")] public BulletData bulletData = new BulletData(); - [Header("ʱ,Ĭ10f")] public float BulletDeadTimer=10f; + [Header("ʱ,Ĭ10f")] public float BulletDeadTimer = 10f; [Header("ӵ")] public Animator animator; - [Header("ӵƶ")] public bool IsMove=true; + [Header("ӵƶ")] public bool IsMove = true; [Header("ӵײ")] public Collider2D Collider2D; - [Header("ӵЧԤ")] public List effectPres=new List(); + [Header("ӵЧԤ")] public List effectPres = new List(); private float timer = 0; [Header("ӵ")] public int NumberOfBulletAttacks = 1; [Header("Ŀ")] public GameObject Target; + [Header("ӵǷĿ")] public bool noLockEnemy=false; + [Header("ӵǷ")] public bool Cansplit = false; + [Header("ӵԤ")] public GameObject smallBulletPrefab; private void Update() { switch (this.bulletMoveType) @@ -97,7 +100,7 @@ public class Bullet : MonoBehaviour if (IsMove) { - if (Target != null&&Target.activeSelf==true) + if (Target != null&&Target.activeSelf==true&&!noLockEnemy) { this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, Target.transform.position, Time.deltaTime * bulletData.BulletSpeed); } @@ -172,6 +175,7 @@ public class Bullet : MonoBehaviour if (animator == null) { + SplitBullet(); attackObj.bulltes.Remove(this.gameObject); Destroy(this.gameObject); } @@ -289,4 +293,28 @@ public class Bullet : MonoBehaviour } } + public void SplitBullet()//ӵ + { + if (Cansplit) + { + // ȡǰӵǰ + Vector3 currentDirection = transform.forward; + + // ɵСӵ + for (int i = 0; i < attackObj.splitNum; i++) + { + // ڵǰƫ + Vector3 randomOffset = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f)); + + // һСӵ + GameObject smallBullet = Instantiate(smallBulletPrefab, transform.position, Quaternion.identity); + smallBullet.GetComponent().role = role; + smallBullet.GetComponent().attackObj=attackObj; + // ΪСӵ÷з򣨵ǰ + ƫƣ + smallBullet.transform.up = currentDirection+randomOffset; + + // Сӵ߼繥ԡڵ + } + } + } } diff --git a/Role/Role.cs b/Role/Role.cs index 7cd0052..404b0a1 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -31,7 +31,8 @@ public enum CharacterFlags big = 1 << 2, min = 1 << 3, - FlyBig=fly|big, + + FlyBig =fly|big, FlyMin=fly|min, LandBig = land | big, LandMin = land | min, @@ -561,6 +562,15 @@ public class Role : Fun hurt *= (1 + mySkillUp.DamageOfland); //Debug.LogError("地面敌人加成"); } + if (Target.GetComponent().isSlowed) // 如果敌人减速 + { + hurt *= (1 + mySkillUp.DamageOfSlow); + UnityEngine.Debug.Log("减速敌人加成"); + } + + + hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent()));//计算五行属性伤害 + hurt *= HujiaDamage(Target.gameObject.GetComponent());//计算破甲伤害 if (hurt * (1 - TargetDefense / 100) < 1) { @@ -568,11 +578,8 @@ public class Role : Fun } else { - hurt *=(1- TargetDefense/100) ; + hurt *= (1 - TargetDefense / 100); } - - hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent()));//计算五行属性伤害 - hurt *= HujiaDamage(Target.gameObject.GetComponent());//计算破甲伤害 if (GetComponent()) { GetComponent().HarmNumber += Mathf.Round(hurt); diff --git a/Role/SmallBullet.cs b/Role/SmallBullet.cs new file mode 100644 index 0000000..c614ddf --- /dev/null +++ b/Role/SmallBullet.cs @@ -0,0 +1,120 @@ +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UIElements; +using System.Linq; + + + + + +public class SmallBullet : Bullet +{ + + + private void Update() + { + switch (this.bulletMoveType) + { + //ӵƶʽƶ + case BulletMoveType.PeerToPeer: + if (IsMove) + { + + + this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed); + + + + + } + + break; + case BulletMoveType.PointToDirection: + break; + case BulletMoveType.Scope: + break; + } + + + + } + + private void OnTriggerEnter2D(Collider2D collision) + { + Role Crole = collision.gameObject.GetComponent(); + if (Crole) + { + if (Crole.camp != role.camp) + { + + + + + + foreach (var buff in role.storageBuff) + { + if (!Crole.PlayerBuff.Contains(buff)) + { + Crole.PlayerBuff.Add(buff); + } + } + + Crole.ApplyBuffs(); + + // Debug.Log(this.role.gameObject.name + "й"); + int direction = 0; + if (collision.transform.position.x > transform.position.x) //ӵ򵽵ߣƮʾұ + { + direction = 1; + } + Crole.bloodLoss(new object[] { Crole, role.DamageCreate(Crole.GetComponent()), attackObj.damageTyp, role }, direction); + + + if (myBulletType != BulletType.Spraying) + { + + + if (animator == null) + { + + + Destroy(this.gameObject); + } + else + { + IsMove = false; //ֹͣƶ + Collider2D.enabled = false; //رײ + transform.position = collision.transform.position; + animator.SetTrigger("Boom"); + + } + } + + + + + + + + + } + } + } + + + private void OnTriggerStay2D(Collider2D collision) + { + + } + + private void OnTriggerExit2D(Collider2D collision) + { + + } + + + +} diff --git a/Role/SmallBullet.cs.meta b/Role/SmallBullet.cs.meta new file mode 100644 index 0000000..d82eb57 --- /dev/null +++ b/Role/SmallBullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81fd92e321a387748864a24a654ec980 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: