NOTE: The correct word to use might be Collect gun, and not Pickup gun.
So I basically have an array to pick up guns and switch between guns. It works well! And I also have the script set up so that when I pickup a new gun, the prefab of the gun gets added to my inventory. The problem is destroying the gun that is on the ground. When I use Destroy, it deletes the prefab. How can make it to just delete the copy on the ground?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUpGun : MonoBehaviour
{
private int counter = 0;
GameObject[ ] gunInv = new GameObject[2];
CharMovement player = new CharMovement();
public int currentGun;
private void Start()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == “Gun”)
{
if (counter < 2)
{
addGunToInventory(other.gameObject);
}
else
{
swap(gameObject.GetComponent().currentGun, other.gameObject);
}
}
else
return;
}
public void addGunToInventory(GameObject gun)
{
print(“hello” + "Picked up " + gun.name);
gunInv[counter] = GameObject.Find(gun.name);
Destroy(gun.gameObject);
gunInv[counter].SetActive(true);
if (counter == 0)
{
gameObject.GetComponent().changeGun(counter);
}
counter++;
print(counter);
}
public void swap(int i, GameObject gun)
{
gunInv*.SetActive(false);*
gunInv = gun;
gunInv*.SetActive(true);*
gameObject.GetComponent().changeGun(i);
}
public GameObject active(int i)
{
currentGun = i;
return gunInv*;*
}
}