I have the following code and while the inspector shows the variable v it never displays the variable a.
What am I doing wrong?
thanks
using UnityEngine;
using System.Collections;
public class LevelObjects : MonoBehaviour
{
public int v=0;
public ClicObject a;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
By default custom C# classes like your ClicObject aren’t serializable, thus they don’t appear in the Inspector. If you want to change that then you have to add a line to explicitly do that:
[System.Serializable]
public class ClicObject
{
public string name;
}
Done!
Tip: when you post code here on the forums, either use the Code button up top or manually wrap it in a code block ([ code ]…[ /code ], without the spaces). I’m going to edit your post so you can see an example.
by doing the same class mess as in JS with inner classes
below code is nothing else than
class scriptName {
var coolClass: CoolClass
class CoolClass {
...
}
}
Here is corresponding dummy code (working)
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public CoolClass coolClass;
[System.Serializable]
public class CoolClass {
public int test;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
I had tried something very similar to that, but it didn’t work. When I did it exactly like you did, it did work. Maybe I made a capitalization error the first time?
So there is another solution which is to make the variable public , you will find them showing up in the inspector :
public class VariableTest : MonoBehaviour {
public int health ;
public float myspeed = 10.0f;
public string someString = "this is a test";
public string some_name = "fred";
public bool someSeeting = true;
public GameObject someObject ;
// Use this for initialization
void Start ()
{...