NullReferenceException: Object reference not set to an instance of an object
BeerPickup.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/BeerPickup.cs:13)
When I added the audio clip and added the code for it the error started. Destroy on pickup worked before that part was added. My overrides are updated. Itâs definitely reading the collision since it gives the error every time I touch the pickup
OK, Looks like itâs the camera then. I see a prefab called âCamerasâ. I donât know how many cameras are in there, but if none of them are marked with the âMainCameraâ tag, then Camera.main will be null. Unity usually creates a scene with a camera with a âMainCameraâ tag, but it doesnât assign that tag to any new cameras
Edit: You also donât need the Audio Sources on the beer prefabs because you are not using them. The AudioSource.PlayClipAtPoint(...) is going to create a new audio source at the position you give it, and it will destroy it again once the clip has played
I changed the main camera to âfollow cameraâ but Iâm getting the same error. I also deleted the pickup script from my prefab and reset it. So confused why the destroy on collision worked before the audio part was added. I would have thought Destroy would still work and not audio if anything?