So this script is supposed to create a new randomly placed gas canister after the player triggers the 2d collider around it. But the gas can isn’t destroyed after the player touches it,(I have a collider around it set as trigger). Also the sidebar thing showing objects shows multiple objects being created for seemingly no reason, but they aren’t showing up on screen.
using UnityEngine;
using System.Collections;
public class spawncan : MonoBehaviour {
public GameObject gascan;
public int numofcans = 1;
// Use this for initialization
void Start () {
Vector3 start = new Vector3 (10,10,10);
Instantiate(gascan, start, Quaternion.identity);
}
// Update is called once per frame
void Update () {
if (numofcans == 0)
{
Vector3 pos = new Vector3(Random.Range(-35, 35), Random.Range(-25, 25), 10);
Instantiate(gascan, pos, Quaternion.identity);
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
Destroy(gascan);
numofcans = 0;
}
}
}