I have been coding a combat system for my platformer, and I am now getting NullReferenceException: Object reference not set to an instance of an object
But I just cant find where, Here is the code segment where the error is. health is declared at the start of the function and hit is a raycast2D
if(hit != null){
health = hit.transform.gameObject.GetComponent<Health>(); //Debugger says error is on this line
if(health != null){
succesful = true;
health.hit (secondaryPower);
}else{
succesful = false;
}
I am probably just being stupid again, thanks for any help you may give.