81 lines
2.4 KiB
C#
81 lines
2.4 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;
|
|
[Header("Effects")]
|
|
[SerializeField] private Transform chargeMeter;
|
|
protected override void AbilityEffects()
|
|
{
|
|
if (currentChargeCooldown > 0)
|
|
{
|
|
ShootBullet(projectile, power);
|
|
}
|
|
else
|
|
{
|
|
currentMouseHoldTime = mouseHoldTime;
|
|
}
|
|
}
|
|
|
|
private void ShootBullet(Projectile projectileToShoot, int damage)
|
|
{
|
|
WaveManager.instance.audioSource.PlayOneShot(projectileToShoot.projectileShootSFX, projectileToShoot.volume);
|
|
direction = cam.ScreenToWorldPoint(Input.mousePosition);
|
|
Projectile newProjectile = Instantiate(projectileToShoot, origin.position, Quaternion.identity);
|
|
newProjectile.transform.Lookat2D(direction);
|
|
newProjectile.damage = damage;
|
|
newProjectile.tag = tag;
|
|
newProjectile.playerBullet = true;
|
|
GameManager.instance.projectilesShot++; //i shouldn't be directly modifying the variable but i don't actually care
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
if (currentMouseHoldTime >= 0)
|
|
{
|
|
currentMouseHoldTime -= Time.deltaTime;
|
|
if (currentMouseHoldTime <= 0 && Input.GetMouseButton(0) && currentChargeTime <= 0)
|
|
{
|
|
currentChargeTime += mouseHoldTime;
|
|
isCharging = true;
|
|
}
|
|
else if (Input.GetMouseButtonUp(0))
|
|
{
|
|
ShootBullet(projectile, power);
|
|
}
|
|
}
|
|
if (isCharging && Input.GetMouseButton(0)) //this code REEKS
|
|
{
|
|
currentChargeTime += Time.deltaTime;
|
|
chargeMeter.localScale = new Vector3(Math.Clamp(currentChargeTime, 0, maxChargeTime)/maxChargeTime, 1f, 1f);
|
|
}
|
|
else if (currentChargeTime > 0 && isCharging && Input.GetMouseButtonUp(0))
|
|
{
|
|
ShootBullet(chargedProjectile, power * (int)Math.Clamp(currentChargeTime, 0, maxChargeTime));
|
|
currentChargeTime = 0;
|
|
chargeMeter.localScale = new Vector3(0f, 1f, 1f);
|
|
currentChargeCooldown = chargeCooldown;
|
|
isCharging = false;
|
|
}
|
|
|
|
if (currentChargeCooldown > 0)
|
|
{
|
|
currentChargeCooldown -= Time.deltaTime;
|
|
}
|
|
//Debug.Log(currentChargeTime);
|
|
}
|
|
}
|