You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
1.9 KiB

using System.Collections;
using Ai;
using UnityEngine;
namespace Player
{
public class Shooting : MonoBehaviour
{
[SerializeField] private TargetClosestEnemy _targeting;
[SerializeField] private Bullet _bulletPrefab;
[SerializeField] private int _row = 1;
[SerializeField] private float _delayInRow = 0.3f;
[SerializeField] private GameObject _parent;
[SerializeField] private Vector3 _rotate;
private int _currentRow;
private float _mult;
private float _additionalDamage;
private float _critChance;
public int Row
{
get { return _row; }
set { _row = value; }
}
public Bullet Bullet
{
get { return _bulletPrefab; }
set { _bulletPrefab = value; }
}
public void Shoot()
{
StartCoroutine(BulletsRoutine());
}
private IEnumerator BulletsRoutine()
{
CreateBullets();
_currentRow++;
if (_currentRow >= _row)
{
_currentRow = 0;
yield break;
}
yield return new WaitForSeconds(_delayInRow);
StartCoroutine(BulletsRoutine());
}
private void CreateBullets()
{
var bullet = Instantiate(_bulletPrefab);
var position = transform.position;
bullet.transform.position = position;
var targetPosition = _targeting != null ? _targeting.ClosestPosition() : transform.forward;
var heading = targetPosition - (_parent != null ? _parent.transform.position : position);
var direction = _targeting != null && AiController.Instance.TargetingEnemies.Count > 0
? heading / heading.magnitude
: transform.forward;
if (_rotate != Vector3.zero)
direction = Quaternion.Euler(_rotate) * direction;
bullet.Mult = _mult;
bullet.Init(direction, _additionalDamage, _critChance);
}
public void AddDamage(float value)
{
_additionalDamage += value;
}
public void AddCritChance(float value)
{
_critChance += value;
}
public void SetMult(float itemDamageMult)
{
_mult = itemDamageMult;
}
}
}