Files
FutureMen2/Assets/_FutureMen2/Scripts/Player/PlayerBullet.cs

68 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using DragonLi.Frame;
using UnityEngine;
using Random = UnityEngine.Random;
public enum PlayerWeaponType
{
PlayerWeapon1=1,
PlayerWeapon2=2,
PlayerWeapon3=3,
PlayerWeapon4=4,
PlayerWeapon5=5,
PlayerWeapon6=6,
PlayerWeapon7=7,
PlayerWeapon8=8,
PlayerWeapon9=9,
PlayerWeapon10=10,
}
public class PlayerBullet : MonoBehaviour
{
public PlayerWeaponType bulletType;
private int[] _damages;//伤害
public LayerMask layerMask = ~0;
public Vector3 fixedDirection; // ← 用来存储“第一次”拿到的枪口方向
public Vector3 fixedOrigin; // ← 用来存储“第一次”拿到的枪口位置
public Transform fixedTransform;
/// <summary>
/// 在外层Spawn Laser 的地方)调用,用来把 muzzle.forward/muzzle.position 传进来。
/// </summary>
public virtual void Initialize(Vector3 origin, Vector3 direction,Transform curFixedTransform)
{
fixedOrigin = origin;
fixedDirection = direction.normalized;
fixedTransform = curFixedTransform;
// 我们还可以把 laser.SetPosition(0, origin) 等放到这里
}
private void Awake()
{
layerMask=LayerMask.GetMask("Enemy","Wall","Ground");
}
public virtual void AttackDamage(RaycastHit handlingHit)
{
IDamagable component = handlingHit.transform.GetComponent<IDamagable>();
if (component != null)
{
int randomDamage = GetDamage(out var isCriticalHit);
component.ApplyDamage(randomDamage, isCriticalHit, transform);
}
}
public int GetDamage(out bool isCriticalHit)
{
if(GameManager.Ins.PlayerBulletDataDic.Count>0)
_damages = GameManager.Ins.PlayerBulletDataDic[(int)bulletType].Damage;
int randomDamage = Random.Range(_damages[0]*10, _damages[1]*10);
randomDamage += (Mathf.FloorToInt(GameManager.Ins.buffAtk * randomDamage));
isCriticalHit=randomDamage > (_damages[1] - (_damages[1] - _damages[0]) * 0.35f);
return randomDamage;
}
}