-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeaponPickup.cs
More file actions
75 lines (61 loc) · 1.93 KB
/
WeaponPickup.cs
File metadata and controls
75 lines (61 loc) · 1.93 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
63
64
65
66
67
68
69
70
71
72
73
74
75
using UnityEngine;
public class WeaponPickup : MonoBehaviour
{
[Header("ScriptableObject References")]
[Tooltip("Drag a weapon asset (.asset) here")]
public WeaponSO weaponData;
[Tooltip("Drag global score asset here")]
public GlobalScoreSO globalScore;
[Header("Settings")]
[SerializeField] private bool destroyOnPickup = true;
[SerializeField] private float pickupCooldown = 0.1f;
private bool canPickup = true;
private void OnTriggerEnter(Collider other)
{
if (!canPickup) return;
if (other.CompareTag("Player"))
{
Pickup();
}
}
private void Pickup()
{
if (weaponData == null)
{
Debug.LogError($"[WeaponPickup] {gameObject.name}: weaponData not assigned!");
return;
}
if (globalScore == null)
{
Debug.LogError($"[WeaponPickup] {gameObject.name}: globalScore not assigned!");
return;
}
Debug.Log($"Picked up: {weaponData.weaponName} | Damage: {weaponData.damage} | Attack Speed: {weaponData.attackSpeed}");
globalScore.AddScore(weaponData.damage);
// Pickup effect (optional)
OnPickupEffect();
// Destroy object if needed
if (destroyOnPickup)
{
canPickup = false;
Destroy(gameObject, pickupCooldown);
}
}
private void OnPickupEffect()
{
// Here you can add:
// - play sound
// - spawn particles
// - animation
Debug.Log($"Pickup effect for {weaponData.weaponName}");
}
// Editor-only debugging
private void OnValidate()
{
if (weaponData != null && gameObject.name == "GameObject")
{
// Auto-rename object for convenience
gameObject.name = $"Pickup_{weaponData.weaponName}";
}
}
}