using UnityEngine; public class AmmoPack : MonoBehaviour { public int ammoAmount = 18; public float rotateSpeed = 80f; public float bobHeight = 0.12f; public float bobSpeed = 2.4f; private Vector3 _basePosition; private void Start() { _basePosition = transform.position; } private void Update() { transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime, Space.World); transform.position = _basePosition + Vector3.up * (Mathf.Sin(Time.time * bobSpeed) * bobHeight); } private void OnTriggerEnter(Collider other) { WeaponSwitcher weaponSwitcher = other.GetComponent() ?? other.GetComponentInParent(); if (weaponSwitcher != null && weaponSwitcher.AddAmmoToCurrentWeapon(ammoAmount)) { Destroy(gameObject); } } }