I want to take the mass value from the object that the script is attached to, (the rigidbody), and then divide it by 5 and use it to change the range:
public static float range = 1000;
This is in C# and I don’t really know what to do.
I want to take the mass value from the object that the script is attached to, (the rigidbody), and then divide it by 5 and use it to change the range:
public static float range = 1000;
This is in C# and I don’t really know what to do.
@Josh707 is right: properties of Unity objects can’t be used to initialize member variables (variables declared outside any function) - I suppose that these properties aren’t initialized yet by that time. You must simply declare the variable, and assign to it in Start or Awake:
public static float range;
void Start(){
range = rigidbody.mass / 5;
}
By the way, be aware that static variables are unique: if you have more than one object with this script, range will keep the value assigned by the last Start executed.