- Home /
'MouseLook.sensitivityX' is inaccessible due to its protection level.
I'm getting this error when trying to create a slider GUI to adjust mouse sensitivity while in game? I know the script is correct for accessing the MouseLook Script and variable, but I'm still getting the error:
'MouseLook.sensitivityX' is inaccessible due to its protection level.
any Ideas?
//Look Sensitivity x axis
GUI.Label(Rect(25,125,100,150),"X Axis");
MouseLook.sensitivityX = GUI.HorizontalSlider(Rect(25,150,100,25),MouseLook.sensitivityX, 2.0,15.0);
Answer by Molix · May 03, 2010 at 02:06 AM
If it is talking about protection level, then presumably the variable is not "public", e.g.
public static float sensitivityX;
public static var sensitivityX : float;
It's public in the default version of the script. $$anonymous$$ouseLook is a standard asset, and its definition is "public float sensitivityX;", so unless this person modified their script, this isn't the problem.
Thank you, that was the problem. I don't know why I didn't think of it myself. I hadn't set the var to public, and it's not set that way by default in my version, and I'm using the standard assets version too. so, I dunno what's up, but it works now, thanks.
Correction. When I moved the Var to a static, I accidentally erased the public part. That was my problem. thanks for the help guys.
Answer by qJake · May 03, 2010 at 12:45 AM
You can't just call the sensitivityX property of your script, that's not how the scripting works.
You need to get a reference to the MouseLook script before you can change it. Like this:
// C#
MouseLook ml = GetComponent(typeof(MouseLook)) as MouseLook;
ml.sensitivityX = 1; // or whatever
Well, I've done it with other variables in scripts and it works just fine, this is the first time I've had this error.
That's because those other scripts have their variables set to static. I don't mean to sound harsh, but if you don't know program$$anonymous$$g very well, Unity isn't the best place to start, as there are a lot of quirks that aren't present in regular program$$anonymous$$g.
The sensitivytX variable is set to static as well...
It isn't static in my version of the script (unmodified): http://img98.imageshack.us/img98/7418/nostatic.png - Did you modify it?
um thats not true
a variable does NOT have to be static in order to be accessible by another script thats why we have public and private variables
GetComponent(somescript).somevar=something;
Your answer
Follow this Question
Related Questions
GUI Sliders in the same script. Question (Js.) 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Need help with my script 0 Answers
I need Help With a Speed up script 1 Answer
GUI.HorizontalSlider not working 2 Answers