Sie sind auf Seite 1von 7

First time here? Check out the FAQ!

x
Language: English
Log in
Home
Unity

Industries

Showcase

Asset Store

Learn

Community

Download

Buy

Forums

Answers

Feedback

Issue Tracker

Evangelists

User Groups

Answers

Questions Tags Users Badges Unanswered Ask A Question

Before updating to Windows 10 you may need to return your Pro license. More
information here

C# Variables not showing up in inspector


2

I'm making my game using C# scripts, and the variables aren't appearing in the
inspector, I could just go into the code to edit variables, but having them in the
inspector would be far more convenient.
I've tried every solution I found online, I've tried making the variables public, didn't
work, I corrected any errors in my code, still not appearing, I tried
System.Serializable, nothing.
So what do I do now?
Here's the code I wrote to test it:
1.
2.

using UnityEngine;
using System.Collections;

3.
4.

[System.Serializable]

5.

public class SomeMouseLookScript : MonoBehaviour {

6.
7.

public enum rotationAxis {mouseX = 0, mouseY = 1}

8.

public int mouseXY;

9.
10.

// Use this for initialization

11.

void Start ()

12.

13.
14.

15.
16.

// Update is called once per frame

17.

void Update ()

18.

19.

20.
21.

}
}

22.

I wrote this while following a tutorial, neither variables appeared in the inspector.
c#inspector
more
asked Dec 09, 2012 at 12:58 AM

Cobra!
191 84 67 73
You have to post your script or else nobody will be able to help you.
Dec 09, 2012 at 01:22 AM Lockstep
The mouseXY is showing in the inspector to me, I'm not sure that the enum would
show up.
Dec 09, 2012 at 01:38 AM T27M
4 answers: sort voted first
1
The variables have to be public and part of the class, but not part of any method.
Make sure the script is compiling as any changes won't show if the new script
hasn't compiled.
1.
2.

using UnityEngine;
using System.Collections;

3.
4.

public class MyScript : MonoBehaviour {

5.
6.

public int number = 10;

7.

public string word = "Hello World";

8.
9.
10.
11.

void MyMethod()
{
int anotherNumber = 10;

12.
13.
14.

string anotherWord = "Hello World";

15.

16.

17.

So here the only ones that will show in the inspector and number and word. You
could also try re-adding the script, but I don't think that will be your problem.
more
answered Dec 09, 2012 at 01:21 AM

T27M
1.8k 36 38 46
I'm not sure if this actually is your problem, but is assume the int shows up but you
also want to see the enum. If that is the case, well, an enum is not a variable. It
rather defines a new type of variable. Like if you declare a variable as integer
means, that this variable can have values like {..., -1 , 0 , 1 ,...}. Tu use the enum
you have to declare a new variable as your enum:
1.
2.

public enum rotationAxis {mouseX , mouseY }


public rotationAxis someFancyName;

3.

Then the someFancyName variable will show up in the inspector and you can
choose it to be either mouseX or mouseY. To use the variable inside of your script
you will have to use rotationAxis.mouseX to check for it. Like:
1.
2.

if(someFancyName == rotationAxis.mouseX){

3.

//do something

4.
5.

} else {

6.
7.

//do something else

8.
9.

more
answered Dec 11, 2012 at 04:49 PM

Lockstep
1.9k 34 33 47
If you just edited the script, saved/recompiled, try using Assets>Refresh (Ctrl+R)

more
answered Nov 13, 2013 at 01:13 AM

Paulo Renaux
35 1 4
i dont have enough rep to vote, but +1 for u
May 13, 2014 at 03:00 PM Evorlor
I know this question's old, but another answer that I found solved my run-in with
this problem:

If you've refactored or renamed your script after adding it as a component to an


object, it will stay as a supposedly valid script and will compile etc, but will only
show the variables in the Inspector if your script's name and the class name are the
same (so no ExampleScriptHere and Example_Script_Here nonsense).
more
answered Oct 03, 2013 at 10:34 PM

ketura
01
Your answer

[hide preview]

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

Welcome to Unity Answers


The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Before updating to Windows 10 you may need to return your Pro license. More
information here.

Unity Answers tutorial video!


To help users post good questions and use the site effectively we have posted a tutorial
video. Please check it out.

Topics:
c# x15212
inspector x1009
asked: Dec 09, 2012 at 12:58 AM
Seen: 16862 times
Last Updated: May 13, 2014 at 03:00 PM

Related Questions
Draw more EditorGUILayout components?
Multiple Cars not working
Distribute terrain in zones
Variable has not been assigned error
The name 'Joystick' does not denote a valid type ('not found')
How to control the exposure of public variables in the inspector pane based on a value
of another variable?
Problem using EditorGUILayout.ObjectField with custom type
How to control serialized variables over the inspector pane?
Input variable from Inspector?
Custom Inspector: Targets & GameObjects
about | faq | privacy policy | cookies | contact
Enterprise
Social Q&A

Das könnte Ihnen auch gefallen