So I’m basically trying to make it so when a projectile hits a test dummy I have in the scene, the amount of damage done will be displayed in the console. However, whenever I got it set up it started giving me the following error: “NullReferenceException: object reference not set to an instance of an object”. I was following a tutorial shooting on YouTube, but couldn’t use his code because he uses a variable I don’t have setup, and I’m not sure how to set it up. So to work around it, I just made it so it checks if the object it’s hitting is of the enemy tag type to give the dummy damage. Here’s the YouTube tutorial I was following: 2D Shooting in Unity (Tutorial) - YouTube . Here’s a link to the error: https://i.imgur.com/Yi3VhJs.png and a link to the code: https://i.imgur.com/ETIDYWG.png
Whenever you get a null reference to a object, it means the code can’t find it. So either you didn’t set the object into the inspector within the public asking of GameObject, or the tag wasn’t set to “enemy”. Or even possibly that the collider component isn’t on said object. I have noticed some tutorials leave out key information sometimes, but that’s because once you know something you feel as though it’s just already known, and you don’t mention it. So in all fairness, you either missed something, or the tutorial maker isn’t qualified to make tutorials… lol