57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using cfg.BlacksmithData;
|
||
|
using UnityEngine;
|
||
|
|
||
|
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 float NextTime;
|
||
|
private float time=0;
|
||
|
public bool Start => start;
|
||
|
private bool start=false;
|
||
|
|
||
|
public void SetAttack(ItemData itemData, int a,float sp= 1,int nu=1)
|
||
|
{
|
||
|
_sprite.sprite = AssetBundleManager.ins.Sprite(itemData.Icon, AtlasType.ItemIcon);
|
||
|
attack = a;
|
||
|
speed = sp;
|
||
|
num = nu;
|
||
|
time = BattleManager.ins.NowTime + 10;
|
||
|
start = true;
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter2D(Collider2D other)
|
||
|
{
|
||
|
var mouster=other.GetComponent<Mouster>();
|
||
|
if (!start|| mouster == null) return;
|
||
|
mouster.SetInjured(Attack);
|
||
|
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);
|
||
|
}
|
||
|
}
|