- Home /
Variables not showing in inspector
As the title explains, none of the below variables are showing in inspector, why ?
function Update () {
var speed = 0; //variable for setting the speed of the bullet.
var bulletPrefab:Transform;
var h = Input.GetAxisRaw("Fire1");
// if theres keyboard input fire the bullet
if(h) { Instantiate(bulletPrefab, GameObject.Find("bulletSpawnPoint").transform.position, Quaternion.identity); bulletPrefab.transform.Translate(Vector3(0,0,h + speed)); } }
For a variable to show in the inspector, it has to be declared as a property of the class. Variables that are declared inside methods will not show up in the inspector. For example:
// $$anonymous$$yClass.js
var Speed:float = 0; // This will show in the inspector
function update()
{
var speed:float = 0; // This will not show in the inspector
}
It's a good idea to always strongly type your variables as shown here. If you let the compiler try to guess a variable's type for you, then that can lead to undesirable behavior and bugs.
Answer by Eric5h5 · Jul 08, 2012 at 10:05 PM
Because all of them are inside a function, which makes them local to that function only. (Also please format code correctly when posting.)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073904im_/https://answers.unity.com/themes/thub/images/avi.jpg)