| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using UnityEngine;
- using SoftKitty.InventoryEngine;
- using SoftKitty;
- public class GoldBagPickup : MonoBehaviour
- {
- [Header("Gold Settings")]
- public int goldAmount = 50;
- public int currencyType = 0;
-
- [Header("Pickup Settings")]
- public bool autoPickup = true;
- public float pickupRadius = 2.5f;
- public float pickupDelay = 1f;
-
- [Header("Effects")]
- public ParticleSystem spawnParticles;
- public ParticleSystem pickupParticles;
- public AudioClip pickupSound;
-
- [Header("Visuals")]
- public bool enableBobbing = true;
- public float bobHeight = 0.3f;
- public float bobSpeed = 2f;
- public bool enableRotation = true;
- public float rotationSpeed = 90f;
-
- private Vector3 startPos;
- private Transform player;
- private bool pickedUp = false;
- private bool landed = false;
-
- void Start()
- {
- if (spawnParticles) spawnParticles.Play();
-
- GameObject playerObj = GameObject.FindWithTag("Player");
- if (playerObj) player = playerObj.transform;
-
- Invoke("LandGold", 1f);
- }
-
- void LandGold()
- {
- startPos = transform.position;
- landed = true;
-
- Rigidbody rb = GetComponent<Rigidbody>();
- if (rb) Destroy(rb);
-
- Collider col = GetComponent<Collider>();
- if (col) col.enabled = false;
- }
-
- void Update()
- {
- if (pickedUp || !landed) return;
-
- if (enableBobbing)
- {
- float y = startPos.y + Mathf.Sin(Time.time * bobSpeed) * bobHeight;
- transform.position = new Vector3(startPos.x, y, startPos.z);
- }
-
- if (enableRotation)
- {
- transform.Rotate(Vector3.forward, rotationSpeed * Time.deltaTime);
- }
-
- if (!player) return;
-
- float dist = Vector3.Distance(transform.position, player.position);
- if (dist <= pickupRadius)
- {
- if (autoPickup)
- {
- Pickup();
- }
- else if (Input.GetKeyDown(KeyCode.E))
- {
- Pickup();
- }
- }
- }
-
- void Pickup()
- {
- if (pickedUp) return;
- pickedUp = true;
-
- StartCoroutine(PickupWithDelay());
- }
-
- System.Collections.IEnumerator PickupWithDelay()
- {
- if (ItemManager.PlayerInventoryHolder != null)
- {
- ItemManager.PlayerInventoryHolder.AddCurrency(currencyType, goldAmount);
- }
-
- if (pickupParticles)
- {
- ParticleSystem fx = Instantiate(pickupParticles, transform.position, Quaternion.identity);
- Destroy(fx.gameObject, 2f);
- }
-
- if (pickupSound)
- {
- AudioSource.PlayClipAtPoint(pickupSound, transform.position);
- }
- else
- {
- try { SoundManager.Play2D("Loot"); } catch { }
- }
-
- // Show UI message (uncomment after setting up GoldPickupMessage in Canvas)
- GoldPickupNotifier.Show(goldAmount);
-
- yield return new WaitForSeconds(pickupDelay);
-
- Destroy(gameObject);
- }
-
- void OnDrawGizmosSelected()
- {
- Gizmos.color = Color.yellow;
- Gizmos.DrawWireSphere(transform.position, pickupRadius);
- }
- }
|