- Home /
 
 
               Question by 
               DeemDude · Sep 09, 2021 at 02:38 AM · 
                gameobjectprefabprefabsplayer movement  
              
 
              Create with code 2.2 pizza not shooting
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.
               Comment
              
 
               
              Answer by chernobyyl · Sep 09, 2021 at 06:03 AM
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) 
 }
 
              Your answer