Check distance between items and player not working
I keep getting this error message: "MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. GameManager.Update () (at Assets/Scripts/GameManager.cs:27)"
I am trying to only allow the player to pick up the items if they are in range with the tag "GroundItems". The issue arrises when I 'pick up' the first object, then everything breaks. This script is on my "GameManager" script. I feel like the scrip is wrong (I am very new to coding). Any help would be greatly appreciated!!!!
You are creating the list of GameObjects on your start method, and then checking the same array on every update, even after destroying objects. This means the array still has reference to objects that no longer exist.
$$anonymous$$ove the tags1 initialisation to the first line of your update method and this should resolve your immediate issue.
You're welcome :) could you accept this as the answer? I'm new on here and trying to build my rep :)
Your answer
Follow this Question
Related Questions
Mining from a chunk? - 3d Game Cavern Generation + Player integration 0 Answers
Unity 3D #C Nightvision does not want to switch on or off. 0 Answers
Trying to make a click-and-point kind of thing for an escape game. 0 Answers
Animations that interact with the world around you? 0 Answers
How do I make an object with a rigidbody2D and boxcollider2D not collide with another? 1 Answer