- Home /
Cannot Edit variables?
So im having an issue editing a variable via another script. Im trying to edit the contrast public float, how would i do this.
ive tried "using UnityStandardAssets.CinematicEffects; mainMenuCamera.GetComponent ().BasicsSettings.contrast" but that doesnt work.
I dont know what im doing wrong. can anyone help me? i pretty new to programming and any help would be awesome. Sorry again for my newbieness. here is the first section of the contrast script. Not sure if more of the script is needed, if so just ask for it and ill post it :)
namespace UnityStandardAssets.CinematicEffects
[Serializable]
public struct BasicsSettings
{
[Range(-2f, 2f), Tooltip("Sets the white balance to a custom color temperature.")]
public float temperatureShift;
[Range(-2f, 2f), Tooltip("Sets the white balance to compensate for a green or magenta tint.")]
public float tint;
[Space, Range(-0.5f, 0.5f), Tooltip("Shift the hue of all colors.")]
public float hue;
[Range(0f, 2f), Tooltip("Pushes the intensity of all colors.")]
public float saturation;
[Range(-1f, 1f), Tooltip("Adjusts the saturation so that clipping is minimized as colors approach full saturation.")]
public float vibrance;
[Range(0f, 10f), Tooltip("Brightens or darkens all colors.")]
public float value;
[Space, Range(0f, 2f), Tooltip("Expands or shrinks the overall range of tonal values.")]
public float contrast;
[Range(0.01f, 5f), Tooltip("Contrast gain curve. Controls the steepness of the curve.")]
public float gain;
[Range(0.01f, 5f), Tooltip("Applies a pow function to the source.")]
public float gamma;
public static BasicsSettings defaultSettings
{
get
{
return new BasicsSettings
{
temperatureShift = 0f,
tint = 0f,
contrast = 1f,
hue = 0f,
saturation = 1f,
value = 1f,
vibrance = 0f,
gain = 1f,
gamma = 1f
};
}
}
}
Answer by sohail11330 · Jan 24, 2017 at 08:57 AM
change public float Contrast to public static float Contrast. Use GetComponent< contrast script name>().contrast; in your script or where you want to use contrast value.
it dosent work, im getting 3 errors,
"Assets/Standard Assets/Effects/TonemappingColorGrading/TonemappingColorGrading.cs(281,25): error CS1914: Static field or property UnityStandardAssets.CinematicEffects.TonemappingColorGrading.BasicsSettings.contrast' cannot be assigned in an object initializer" "Assets/Standard Assets/Effects/TonemappingColorGrading/TonemappingColorGrading.cs(281,25): error CS0176: Static member
UnityStandardAssets.CinematicEffects.TonemappingColorGrading.BasicsSettings.contrast' cannot be accessed with an instance reference, qualify it with a type name ins$$anonymous$$d"
"Assets/Standard Assets/Effects/TonemappingColorGrading/TonemappingColorGrading.cs(974,94): error CS0176: Static member `UnityStandardAssets.CinematicEffects.TonemappingColorGrading.BasicsSettings.contrast' cannot be accessed with an instance reference, qualify it with a type name ins$$anonymous$$d"
I have no idea what is happening.
You should not change a Unity Standard Assets script and just make something static. If your own script is attached to the same Camera as the effect try using this: this.GetComponent< TonemappingColorGrading >().BasicsSettings.contrast = 0.5f;
Your answer
![](https://koobas.hobune.stream/wayback/20220612105341im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Accessing other gameobject's script variables : why doesn't this work? 2 Answers
How to access a public string attached on a UI Button 1 Answer
Setting a variable to a variable from another script 1 Answer
fix script to get C# var from another object instead of object this script is attached to 2 Answers
Get Component With Variable Help 2 Answers