2024-12-13 20:38:15 +08:00

64 lines
1.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using cfg.BlacksmithData;
using UnityEngine;
using Random = UnityEngine.Random;
public class Bullet : MonoBehaviour
{
[SerializeField] private SpriteRenderer _sprite;
public int Attack => attack;
private int attack = 0;
private int num = 1;
public float Speed => speed;
private float speed=0;
public int Cri => criti;
private int criti;
public float NextTime;
private float time=0;
public bool Start => start;
private bool start=false;
public void SetAttack(SkillState itemData, int a,float sp= 1,int nu=1,int criticalStrike =0)
{
var skillData=JsonTab.Instance.tables.SkillStructure.Get(itemData.data.Skillbody);
_sprite.sprite = AssetBundleManager.ins.Sprite(skillData.Skillbodyicon, AtlasType.ButtleIcon);
attack = a;
speed = sp;
num = nu;
time = BattleManager.ins.NowTime + 10;
start = true;
criti = criticalStrike;
}
private void OnTriggerEnter2D(Collider2D other)
{
var mouster=other.GetComponent<Mouster>();
if (!start|| mouster == null) return;
var r = criti>Random.Range(0, 100);
var a = r ? Attack : Attack * 1.5;
mouster.SetInjured((int) a);
num -= 1;
if (num<=0)
{
start = false;
BattleManager.ins.RemoveBullets(this);
}
}
public void BulletUpdate()
{
if (!start)
{
return;
}
if (time<BattleManager.ins.NowTime)
{
start = false;
BattleManager.ins.RemoveBullets(this);
}
transform.Translate(transform.up*Speed* Time.deltaTime,Space.World);
}
}