What I am trying to do:
Create a class that will allow me to easily change all kinds of public float variables from inside the game for VR development; So I have a slider ingame to allow me to test out many values without constantly putting on and taking off the headset to change the value in the editor.
The Problem:
I am trying to keep the class as generic as possible so I can use it for all kinds of variables , as long as they are float type and publicly accessible.
However, I am not sure how to easily store a reference to the variable instead of just the value. I have searched for things like pointers or saving variables as strings but both come with tons of warnings not to do it.
The closest I have come to what I want is the “ref” keyword but I am not sure how to keep the reference outside of the function so I can still use the reference later in another function of the same class. I hope the code below makes it clear what I want to do.
I am open for suggestions for other ways to do this as long as it allows me to easily use this with for example both a rigidbody mass and a player starting health (assuming they are both publicly accessible values). Thanks in advance!
The Code:
public class SliderDebugVar {
private float referencedFloat;
public SliderDebugVar(ref float aReferencedFloat)
{
referencedFloat = aReferencedFloat; //How do I keep the original reference here?
}
private void ChangeFloatFromSlider()
{
referencedFloat = 10f; //How to make this change aReferencedFloat and as a consequence also the original value?
}
}