Hey everyone, I have my code set up to instantiate a “fuel” game object on an enemy kill that the player can then collide with to collect that object. The problem I have run into is when I have multiple fuel objects on the ground when the player runs over a specific one it makes the first created object disappear instead of the one the player is colliding with. I am also able to modify my code to make them all disappear at the same time but that doesn’t really help either. I don’t know if there would be an easy way to fix this but the only way I have seen is using an array but I’m not sure where to start with that.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FuelPickup : MonoBehaviour {
public GameObject Fuel;
public float ammo;
void Start()
{
}
void Update()
{
}
void OnTriggerEnter (Collider col)
{
if(col.gameObject.tag == "Fuel")
{
Fuel = GameObject.FindGameObjectWithTag("Fuel");
Destroy(Fuel);
if (ammo < 100)
{
ammo++;
Debug.Log(ammo);
}
}
}
}