I am doing create with code lesson 2.2 and I’m trying to make the pizza be destroyed offscreen. Everything works until the first pizza is destroyed and then you can’t shoot pizza anymore. it also says that the GameObject has been destroyed and I am still trying to access it.
Hello DeemDude
Can you show us your code?
The Error says that you used the Destroy() function on an object, an then still try to access it. So, the object doesn’t exist anymore.
Example:
public GameObject enemy; // Gets defined in the inspector
void Start() {
// Destroying the object
Destroy(enemy)
// trying to access the object
Debug.Log(enemy.name)
}
I’m having this same issue, any luck yet?,Hi @chernobyyl I’m having the same issue. Here is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyOutofBounds : MonoBehaviour
{
private float topBound = 40;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.z > topBound)
{
Destroy(gameObject);
}
}
}