- Home /
Modify a float value
Hello, I'm trying for some time now to modify a float value from the new post processing profile but I can't figure out how. I know i need to create a temporary variable but so far I've just used this for positions in which i used Vector3 but now i just need to modify a single float value. I'm trying the line below which is wrong of course. To avoid any confusion my question has nothing to do with the post processing script, i just want to know how to modify a float value that requires to be stored in a temporary variable.
PostProcessingProfileScript.bloom.settings.bloom.threshold -= new float (0.05f);
Answer by Taylor-Libonati · Dec 27, 2017 at 09:21 PM
I think the reason that wouldn't work is because you are using the -= modifier. I think you would do exactly what you said "store in a temporary variable" and then reassign it. So something like this:
float myFloat = PostProcessingProfileScipt.bloom.settings.bloom.thresholdPostProcessingProfileScipt.bloom.settings.bloom.threshold
myFloat += .05f;
PostProcessingProfileScipt.bloom.settings.bloom.threshold = myFloat;
Are you using the PostProcessingStack v2? If the above doesn't work let me know what variable you are trying to modify and I can try it out.
EDIT: OH! I think I get it now. The float isn't the thing that needs to be a temporary variable, it is either the settings, or the bloom class. My guess is the settings. So try creating a settings variable and saving the bloom.settings to it. Modify that, then assign it back. I don't have PostProcessingProfileScipt in my project so I can't test it.
Thanks for the quick reply. I tried it and it's not working. Also the last line gives me the typical error "...Consider storing the value in a temporary variable". Here is my code:
void Update ()
{
float myFloat = PostProcessingProfileScript.bloom.settings.bloom.threshold;
//PostProcessingProfileScript.bloom.settings.bloom.threshold = myFloat;
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.T))
{
myFloat -= 0.05f;
}
}
I found a simpler workaround. I used the Legacy Cinematic Image Effects which is pretty much the same but as a seperate script that you can attach to the camera and then modify a value directly! Here is a part of the code for anyone that may need it.
First you need to use this on top:
using UnityStandardAssets.CinematicEffects;
Then you can modify a value directly without storing it in a temporary var.
BloomScript.settings.threshold -= 0.05f;
Oh odd, well I made an edit in my answer that I think is the actual solution. But that's cool it is working.
Your answer
Follow this Question
Related Questions
How do i declare a negative float while initializing a vector? 1 Answer
New User Questions 1 Answer
Where do I start with unity? 3 Answers
Why is my game slow when i export it to Windows? 1 Answer
BCE0044 error help me please 1 Answer