74 lines
1.9 KiB
C#
74 lines
1.9 KiB
C#
using System;
|
|
using Core.Extensions;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
public class ReisenShoot : Ability
|
|
{
|
|
[SerializeField] private Projectile projectile;
|
|
[SerializeField] private Projectile chargedProjectile;
|
|
[SerializeField] private Camera cam;
|
|
[Header("Charge")]
|
|
[SerializeField] private float mouseHoldTime;
|
|
private float currentMouseHoldTime;
|
|
private float currentChargeTime;
|
|
private bool isCharging;
|
|
[SerializeField] private float maxChargeTime;
|
|
[SerializeField] private float chargeCooldown;
|
|
private float currentChargeCooldown;
|
|
protected override void AbilityEffects()
|
|
{
|
|
if (currentChargeCooldown > 0)
|
|
{
|
|
ShootBullet(projectile, power);
|
|
}
|
|
else
|
|
{
|
|
isCharging = true;
|
|
}
|
|
}
|
|
|
|
private void ShootBullet(Projectile projectileToShoot, int damage)
|
|
{
|
|
direction = cam.ScreenToWorldPoint(Input.mousePosition);
|
|
Projectile newProjectile = Instantiate(projectileToShoot, origin.position, Quaternion.identity);
|
|
newProjectile.transform.Lookat2D(direction);
|
|
newProjectile.damage = damage;
|
|
newProjectile.tag = tag;
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
if (currentMouseHoldTime >= 0)
|
|
{
|
|
currentMouseHoldTime -= Time.deltaTime;
|
|
if (currentMouseHoldTime <= 0 && Input.GetMouseButton(1) && currentChargeTime <= 0)
|
|
{
|
|
isCharging = true;
|
|
}
|
|
else if (Input.GetMouseButtonUp(0))
|
|
{
|
|
ShootBullet(projectile, power);
|
|
}
|
|
}
|
|
if (isCharging && Input.GetMouseButton(0)) //this code REEKS
|
|
{
|
|
currentChargeTime += Time.deltaTime;
|
|
}
|
|
else if (isCharging && Input.GetMouseButtonUp(0))
|
|
{
|
|
Debug.Log("here");
|
|
currentChargeTime = 0;
|
|
ShootBullet(chargedProjectile, power * (int)Math.Clamp(currentChargeTime, 0, maxChargeTime));
|
|
currentChargeCooldown = chargeCooldown;
|
|
isCharging = false;
|
|
}
|
|
|
|
if (currentChargeCooldown > 0)
|
|
{
|
|
currentChargeCooldown -= Time.deltaTime;
|
|
}
|
|
Debug.Log(currentChargeTime);
|
|
}
|
|
}
|