I’m a minute from absolutely raging on my computer. I have a script that applies a “buoyancy force” to an object in water (in my case a trigger box). It was working just fine until the other day where out of no where Unity is telling me that floatingRigidbody.AddForce(force) isn’t set to an instance of an object. Which makes no sense, because the variable floatingRigidbody is a public GameObject which gets assigned when an object enters a trigger.
public GameObject floatingRigidbody;
void OnTriggerStay(Collider other) {
if(other.gameObject.GetComponent<Rigidbody>() && other.gameObject.tag != "Player") {
isUnderWater = true;
floatingRigidbody = other.gameObject;
clampPercentage();
}
}
This code ran fine before. Now the whole NullReferenceException error is keeping the script from running. I don’t know why this is happening and it seems to happen often. and YES I have done the whole if(floatingRigidbody != null) thing, and that doesn’t work either. Is there a hero out there that can save my computer from complete destruction?