水鲨鱼

This commit is contained in:
GL 2025-01-03 18:02:54 +08:00
parent e828d3c14c
commit 2d4dd3e1c9
5 changed files with 220 additions and 9 deletions

View File

@ -38,6 +38,8 @@ public class Attack : MonoBehaviour
[Header("攻击持续时间")] public float AttackStayTime;// [Header("攻击持续时间")] public float AttackStayTime;//
[Header("攻击目标")] public GameObject Target; [Header("攻击目标")] public GameObject Target;
[Header("攻击范围显示脚本")] public CharacterClick characterClick; [Header("攻击范围显示脚本")] public CharacterClick characterClick;
[Header("攻击随机角度范围")] public float Angle=30;
[Header("子弹分裂个数")] public int splitNum = 2;
public bool isAttack = true; public bool isAttack = true;
public bool flag = false; public bool flag = false;
[HideInInspector] public float timer = 0; [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<Bullet>().role = role;
BulletGamobj.GetComponent<Bullet>().attackObj = this;
BulletGamobj.GetComponent<Bullet>().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd);
BulletGamobj.GetComponent<Bullet>().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);
}
}
} }

View File

@ -80,14 +80,17 @@ public class Bullet : MonoBehaviour
[Header("子弹属性")] public BulletAttributes bulletAttributes; [Header("子弹属性")] public BulletAttributes bulletAttributes;
[Header("攻击类型")] public BulletMoveType bulletMoveType; [Header("攻击类型")] public BulletMoveType bulletMoveType;
[Header("子弹数据")] public BulletData bulletData = new BulletData(); [Header("子弹数据")] public BulletData bulletData = new BulletData();
[Header("销毁时间,默认是10f")] public float BulletDeadTimer=10f; [Header("销毁时间,默认是10f")] public float BulletDeadTimer = 10f;
[Header("子弹动画")] public Animator animator; [Header("子弹动画")] public Animator animator;
[Header("子弹移动参数")] public bool IsMove=true; [Header("子弹移动参数")] public bool IsMove = true;
[Header("子弹碰撞体")] public Collider2D Collider2D; [Header("子弹碰撞体")] public Collider2D Collider2D;
[Header("子弹特效预制体")] public List<GameObject> effectPres=new List<GameObject>(); [Header("子弹特效预制体")] public List<GameObject> effectPres = new List<GameObject>();
private float timer = 0; private float timer = 0;
[Header("子弹攻击数量")] public int NumberOfBulletAttacks = 1; [Header("子弹攻击数量")] public int NumberOfBulletAttacks = 1;
[Header("攻击目标")] public GameObject Target; [Header("攻击目标")] public GameObject Target;
[Header("子弹是否不锁定目标")] public bool noLockEnemy=false;
[Header("子弹是否会分裂")] public bool Cansplit = false;
[Header("分裂子弹的预制体")] public GameObject smallBulletPrefab;
private void Update() private void Update()
{ {
switch (this.bulletMoveType) switch (this.bulletMoveType)
@ -97,7 +100,7 @@ public class Bullet : MonoBehaviour
if (IsMove) 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); 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) if (animator == null)
{ {
SplitBullet();
attackObj.bulltes.Remove(this.gameObject); attackObj.bulltes.Remove(this.gameObject);
Destroy(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<SmallBullet>().role = role;
smallBullet.GetComponent<SmallBullet>().attackObj=attackObj;
// 为小子弹设置飞行方向(当前方向 + 随机偏移)
smallBullet.transform.up = currentDirection+randomOffset;
// 处理小子弹的相关逻辑,例如攻击属性、生命周期等
}
}
}
} }

View File

@ -31,7 +31,8 @@ public enum CharacterFlags
big = 1 << 2, big = 1 << 2,
min = 1 << 3, min = 1 << 3,
FlyBig=fly|big,
FlyBig =fly|big,
FlyMin=fly|min, FlyMin=fly|min,
LandBig = land | big, LandBig = land | big,
LandMin = land | min, LandMin = land | min,
@ -561,6 +562,15 @@ public class Role : Fun
hurt *= (1 + mySkillUp.DamageOfland); hurt *= (1 + mySkillUp.DamageOfland);
//Debug.LogError("地面敌人加成"); //Debug.LogError("地面敌人加成");
} }
if (Target.GetComponent<enemy>().isSlowed) // 如果敌人减速
{
hurt *= (1 + mySkillUp.DamageOfSlow);
UnityEngine.Debug.Log("减速敌人加成");
}
hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent<enemy>()));//计算五行属性伤害
hurt *= HujiaDamage(Target.gameObject.GetComponent<enemy>());//计算破甲伤害
if (hurt * (1 - TargetDefense / 100) < 1) if (hurt * (1 - TargetDefense / 100) < 1)
{ {
@ -568,11 +578,8 @@ public class Role : Fun
} }
else else
{ {
hurt *=(1- TargetDefense/100) ; hurt *= (1 - TargetDefense / 100);
} }
hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent<enemy>()));//计算五行属性伤害
hurt *= HujiaDamage(Target.gameObject.GetComponent<enemy>());//计算破甲伤害
if (GetComponent<enemy>()) if (GetComponent<enemy>())
{ {
GetComponent<enemy>().HarmNumber += Mathf.Round(hurt); GetComponent<enemy>().HarmNumber += Mathf.Round(hurt);

120
Role/SmallBullet.cs Normal file
View File

@ -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<Role>();
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<Role>()), 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)
{
}
}

11
Role/SmallBullet.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81fd92e321a387748864a24a654ec980
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: