x


'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);
more ▼

asked May 03 '10 at 12:24 AM

CalledToGaming gravatar image

CalledToGaming
190 21 24 30

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
more ▼

answered May 03 '10 at 02:06 AM

Molix gravatar image

Molix
4.8k 16 27 66

It's public in the default version of the script. MouseLook is a standard asset, and its definition is "public float sensitivityX;", so unless this person modified their script, this isn't the problem.

May 03 '10 at 02:07 AM qJake

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.

May 03 '10 at 02:29 AM CalledToGaming

Correction. When I moved the Var to a static, I accidentally erased the public part. That was my problem. thanks for the help guys.

May 03 '10 at 02:32 AM CalledToGaming
(comments are locked)
10|3000 characters needed characters left

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
more ▼

answered May 03 '10 at 12:45 AM

qJake gravatar image

qJake
11.6k 43 78 161

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.

May 03 '10 at 12:51 AM CalledToGaming

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 programming very well, Unity isn't the best place to start, as there are a lot of quirks that aren't present in regular programming.

May 03 '10 at 01:17 AM qJake

The sensitivytX variable is set to static as well...

May 03 '10 at 01:20 AM CalledToGaming

It isn't static in my version of the script (unmodified): http://img98.imageshack.us/img98/7418/nostatic.png - Did you modify it?

May 03 '10 at 02:00 AM qJake

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;

Oct 29 '12 at 02:41 AM lil_billy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5085
x3690
x3332
x984
x103

asked: May 03 '10 at 12:24 AM

Seen: 5290 times

Last Updated: Oct 29 '12 at 02:41 AM