111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
public enum BulletType
|
|
{
|
|
Bullet,
|
|
Lightning,
|
|
Spraying //原地喷射
|
|
|
|
}
|
|
|
|
public enum BulletMoveType
|
|
{/// <summary>
|
|
/// 子弹移动方式:点对点,
|
|
/// </summary>
|
|
PeerToPeer,
|
|
/// <summary>
|
|
/// 方向移动
|
|
/// </summary>
|
|
PointToDirection,
|
|
Scope
|
|
}
|
|
|
|
|
|
public class BulletData
|
|
{
|
|
[Header("子弹穿透次数")] public int NumberOfBulletPenetrations = 1;
|
|
/// <summary>
|
|
/// 子弹散射次数
|
|
/// </summary>
|
|
[Header("子弹散射次数")] public int BulletScattering = 1;
|
|
[Header("子弹连发次数")] public int BulletBurstTimes = 1;
|
|
[Header("子弹连发间隔")] public float BulletBurstInterval ;
|
|
[Header("子弹穿透衰减")] public float BulletPenetrationAttenuation = 0.2f;
|
|
[Header("子弹飞行速度")] public float BulletSpeed = 5f;
|
|
[Header("子弹攻击冷却")] public float BulletAttackCooldown = 1f;
|
|
[Header("子弹伤害")] public float attack = 10;
|
|
public BulletData()
|
|
{
|
|
|
|
}
|
|
public BulletData(int numberOfBulletPenetrations, int bulletScattering, int bulletBurstTimes, float bulletBurstInterval, float bulletPenetrationAttenuation, float bulletSpeed, float bulletAttackCooldown)
|
|
{
|
|
NumberOfBulletPenetrations = numberOfBulletPenetrations;
|
|
BulletScattering = bulletScattering;
|
|
BulletBurstTimes = bulletBurstTimes;
|
|
BulletBurstInterval = bulletBurstInterval;
|
|
BulletPenetrationAttenuation = bulletPenetrationAttenuation;
|
|
BulletSpeed = bulletSpeed;
|
|
BulletAttackCooldown = bulletAttackCooldown;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return
|
|
$"{nameof(NumberOfBulletPenetrations)}: {NumberOfBulletPenetrations}, {nameof(BulletScattering)}: {BulletScattering}, {nameof(BulletBurstTimes)}: {BulletBurstTimes}, {nameof(BulletBurstInterval)}: {BulletBurstInterval}, {nameof(BulletPenetrationAttenuation)}: {BulletPenetrationAttenuation}, {nameof(BulletSpeed)}: {BulletSpeed}, {nameof(BulletAttackCooldown)}: {BulletAttackCooldown}";
|
|
}
|
|
}
|
|
public class Bullet : MonoBehaviour
|
|
{
|
|
[Header("子弹发射角色对象")] public Role role;
|
|
[Header("子弹发射范围对象")] public Attack attackObj;
|
|
[Header("子弹类型")] public BulletType myBulletType;
|
|
[Header("攻击类型")] public BulletMoveType bulletMoveType;
|
|
[Header("子弹数据")] public BulletData bulletData = new BulletData();
|
|
[Header("销毁时间,默认是10f")] public float BulletDeadTimer=10f;
|
|
private float timer = 0;
|
|
private void Update()
|
|
{
|
|
switch (this.bulletMoveType)
|
|
{
|
|
//更具子弹的移动方式来移动
|
|
case BulletMoveType.PeerToPeer:
|
|
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
|
|
timer += Time.deltaTime;
|
|
if (timer > BulletDeadTimer)
|
|
{
|
|
Destroy(this.gameObject);
|
|
}
|
|
break;
|
|
case BulletMoveType.PointToDirection:
|
|
break;
|
|
case BulletMoveType.Scope:
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
Debug.Log("进入检测范围");
|
|
Role Crole = collision.gameObject.GetComponent<Role>();
|
|
if(Crole)
|
|
{
|
|
if(Crole.camp!= role.camp)
|
|
{
|
|
Debug.Log("进行攻击计算");
|
|
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role });
|
|
Destroy(this.gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|