Public Variable not showing up in inspector

I just started learning about unity and i seem to have hit a problem.

The public variables that i declared in the script do not seem to show up in the inspector in unity. Is there anyway i can make them show up in the inspector?

using UnityEngine;
using System.Collections;


[System.Serializable]
public class Boundary {
    public float xMin;
    public float xMax;
    public float zMin;
    public float zMax;
}


public class Shipcontroller : MonoBehaviour {

    // Use this for initialization
    public float speed;

    public Boundary boundary;

    public float tilt;
   
    // Update is called once per frame
    void FixedUpdate () {
        float moveHori = Input.GetAxis("Horizontal");
        float moveVeri = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3 (moveHori, 0.0f, moveVeri);
        rigidbody.velocity = movement * speed;

        rigidbody.position = new Vector3 (

                Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
            0, 0f,
                Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)



                );
        rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    }
}


1924131–124271–Shipcontroller.cs (874 Bytes)

One’s ShipController, one’s PlayerController, and another is Shipcontroller2 lol. They need to match up!

I matched them up. but there was no difference. the variables still dont show up.

1924145--124261--Screen Shot 2015-01-17 at 2.55.16 PM.png
1924145--124262--Screen Shot 2015-01-17 at 2.55.21 PM.jpg

I may be misreading your piccys but It looks like the file ShipController contains a class PlayerController.
I thought the Class name and File name had to be the same … ?

I changed the class name to match with the file name but the problem still persists

First, please post your code in your post next time, preferably in code tags. Can’t copy and paste from images.

Second, classes don’t have to be in a file of the same name.

Third, the only possibility I can really think of is that Unity’s serialization doesn’t like your formatting. Try splitting line 7 into multiple declarations.

Well this is my first time posting .Will not do that again .
i split line 7 into multiple declarations but the variables still don’t show up in the inspector.

Post the script, such that others can give it a try.
I quickly created a comparable script and it worked as expected. Did you make sure that you don’t have another Shipcontroller class in another namespace and you are using that one in the game object?

For what it’s worth, for me, only the class that has the same name as the script is serialised.

// Variables.cs
using UnityEngine;
using System.Collections;


[System.Serializable]
public class Boundary
{
    public float xMinB, xMaxB, zMinB, zMaxB;
}

[System.Serializable]
public class Variables : MonoBehaviour
{
    public float xMin, xMax, zMin, zMax;
}


[System.Serializable]
public class BoundaryAlt
{
    public float xMinA;
    public float xMaxA;
    public float zMinA;
    public float zMaxA;
}

1924131–124271–Shipcontroller.cs (874 Bytes)

I don’t have another Shipcontroller class in another namespace

You have a compilation error in your script. That’s the reason it is not working. You always have to get rid of every compilation error before you can actually work with the script.

If you change the line with

to

everything should work as expected.

2 Likes

om1972,
For code use the code tags please.

1 Like

Fixed the error and the variables show up in the inspector. i do not know how i could have missed that.Thank you so much .

Weird how your screenshots didn’t show any errors in the bottom console.

If you are looking at the console window, make sure the little red ball near the upper right (inside the window chrome itself) is enabled. Sometimes when closing the console window you can hit that instead and it hides all your errors, but you still can’t get anywhere until you fix them.

1 Like