using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BNG { public class BulletInsert : MonoBehaviour { /// /// The weapon we will be adding Bullets to /// public RaycastWeapon Weapon; /// /// Only transforms that contains this name will be accepted as bullets /// public string AcceptBulletName = "Bullet"; public AudioClip InsertSound; void OnTriggerEnter(Collider other) { Grabbable grab = other.GetComponent(); if (grab != null) { if(grab.transform.name.Contains(AcceptBulletName)) { // Weapon is full if(Weapon.GetBulletCount() >= Weapon.MaxInternalAmmo) { return; } // Drop the bullet and add ammo to gun grab.DropItem(false, true); grab.transform.parent = null; GameObject.Destroy(grab.gameObject); // Up Ammo Count GameObject b = new GameObject(); b.AddComponent(); b.transform.parent = Weapon.transform; // Play Sound if(InsertSound) { VRUtils.Instance.PlaySpatialClipAt(InsertSound, transform.position, 1f, 0.5f); } } } } } }