Unparalleled problem with if-statement
Hello! I have a very strange problem because during game, once every three times "if" statement is not carried out and shows us error, that it can't find object.
This is Script: If player is on the sand texture:
if(hit.collider.material.name == sandPhysicsMaterial.name + " (Instance)"){
Debug.Log("Collider name ma nazwe: "+hit.collider.material.name+" zas gras material: "+sandPhysicsMaterial.name + " (Instance)");
SetWheelStiffnessByGroundPhysic(2f);}
If player is on the grass texture:
else if(hit.collider.material.name == grassPhysicsMaterial.name + " (Instance)"){
Debug.Log("Collider name ma nazwe: "+hit.collider.material.name+" zas gras material: "+grassPhysicsMaterial.name + " (Instance)");
SetWheelStiffnessByGroundPhysic(3f);}
If player is on the asphalt texture:
(...) else {SetWheelStiffnessByGroundPhysic (1f);
}
The script works on that when car will enter on the particular texture it will change the stiffness of the wheel: which works fine, but I do not know why when car enters the texture simply means a "Grass" is set in the new phisicsMaterial and at that moment that every 2-3 frame we've get an error. Can someone please help?
Whenever you get an error, post it with the question. The error is there to tell us what goes wrong and where (possible line number)
O$$anonymous$$G, sorry, I forgot about photo! I uploaded it already.