-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerFireballAttack.cs
More file actions
62 lines (51 loc) · 2.03 KB
/
PlayerFireballAttack.cs
File metadata and controls
62 lines (51 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerFireballAttack : MonoBehaviour{
public SolanaHandler solanaHandler;
private PlayerSettings playerSettings;
public GenericSkillCooldown cooldownManager;
public GameObject fireballPrefab;
public Transform bulletSpawn;
private bool canAttack = true;
private float nextAttackPossible = 0f;
private int charges = 0;
void Start(){
if (solanaHandler == null) {
solanaHandler = GameObject.Find("SolanaHandler").GetComponent<SolanaHandler>();
}
playerSettings = PlayerSettings.getInstance();
charges = 0;
cooldownManager.updateSkillCooldown(Time.time, 0, charges, playerSettings.MaxFireballCharges);
}
void Update(){
if (Time.time > nextAttackPossible) {
canAttack = true;
if(charges < playerSettings.MaxFireballCharges) {
charges += 1;
nextAttackPossible = Time.time + playerSettings.FireballCooldown;
cooldownManager.updateSkillCooldown(Time.time, nextAttackPossible, charges, playerSettings.MaxFireballCharges);
}
}
}
public void fire() {
if (solanaHandler.usdc < 1) {
Debug.Log("no usdc.");
return;
// do nothing
}
if (!canAttack) {
return;
}
// fire!
Vector3 shotDirection = bulletSpawn.transform.forward.normalized;
GameObject bullet = Instantiate(fireballPrefab, bulletSpawn.position, Quaternion.identity);
bullet.GetComponent<Rigidbody>().AddForce(shotDirection * playerSettings.FireballAttackForce);
charges -= 1;
nextAttackPossible = Time.time + playerSettings.FireballCooldown;
if (charges == 0) {
canAttack = false;
}
cooldownManager.updateSkillCooldown(Time.time, nextAttackPossible, charges, playerSettings.MaxFireballCharges);
}
}