Scripting error

So, google isnt really helping as its just more and more confusing me soo I hope you guys can help me

Trying to make a ground checky scripty thingy fixy

NullReferenceException: Object reference not set to an instance of an object
GroundCheck.OnTriggerEnter2D (UnityEngine.Collider2D col) (at Assets/scripts/GroundCheck.cs:16)

NullReferenceException: Object reference not set to an instance of an object
GroundCheck.OnTriggerExit2D (UnityEngine.Collider2D col) (at Assets/scripts/GroundCheck.cs:22)


Edit: Forgot to add this, this is the “Player” script

2265963--151710--buggerino.jpg

Your start method is never going to be executed because it is supposed to be upper case. However, what you have in the start method makes no sense. What are you trying to do there?

I’m new to scripting and stuff so I’m still learning, I am trying to make it so the characters (player) detects the ground and doesnt play the air animation instead i want him to play the idle animation. So basicly groundchecking script if you call it like that. (curently he just plays the air animation all the time beacuse he cant detect the ground)

Firstly, using code tags instead of screenshots will make it easier for people to modify and reshare you code. Otherwise we have to write everything from scratch when trying to assist you.

Next, it’s important to adhere to proper naming conventions. Doing so will make some errors more obvious to you. Generally, variables should all start with a lowercase letter, while your class names start with an uppercase.

So

private player Player;

would become

private Player myPlayer;

assuming you have a class named “Player” in your project.

Moving on. As Dantus said, you must have the Start method capitalized for it to work properly. In all things programming, spelling, capitalization, and punctuation are very important.

In your Start method, it looks like you’re trying to access the player component (should be “Player”) attached to the GameObject in the Player instance (should be “myPlayer” or something). But there’s two problems with this. For one, you haven’t assigned any value to Player/myPlayer, so there’s no gameObject property to even pull in. Once you did have a valid instance to reference, you’re still not doing anything with that player/Player component once you get a reference to it.

I recommend you go through the scripting tutorials to get a better idea of how Unity scripting works. I think it’ll make it perfectly clear why things aren’t working the way you’re expecting them to.

I agree with Schneider for 99%, just want to add that according to the naming converntions private fields should begin with an underscore, so it would become:

private Player _myPlayer;
1 Like