- Home /
Variables inside class not showing up in Inspector C#.
All right, I have a Capsule with rigidbody and a c# script "Walk".
Inside walk, I want to make a public class whose contents can be edited in the Inspector.
It goes like this :
using UnityEngine; using System.Collections;
public class Walk : MonoBehaviour {
public AnimationClip walk;
[System.Serializable]
public class Props {
public float maxSpeed;
}
Animation _animator;
// Use this for initialization
void Start () {
_animator = gameObject.GetComponent();
}
// Update is called once per frame
void Update () {
if (Input.GetAxis("Vertical") == 1){
rigidbody.AddRelativeForce(transform.forward *100);
_animator.CrossFade (walk.name);
}
}
}
However, neither the class nor the contents show up in the Inspector. Can anyone help?
in C# everything is considered private unless specified as you did with animator, but I don't think you can see a variable that is created in a class in the inspector
Answer by pickle chips · Jun 15, 2013 at 03:08 PM
You have to create an instance of the class first, so basically just making a variable of type "your class"
For example, your code should look like this:
public AnimationClip walk;
public Props props; // Add this line in here
[System.Serializable]
public class Props {
public float maxSpeed;
}
This way there is a variable of your class, which will show in the inspector, including all of it's contents.
Answer by Jamora · Jun 15, 2013 at 02:46 PM
You need to either create a custom editor for your class or create a serialized field of the inner class in order to show it on the inspector.
Try this:
[SerializeField]
Props props = new Props();
[System.Serializable]
public class Props {
public float maxSpeed;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Make custom editor for generic class to apply to all current and future child classes 1 Answer
Classes and Scripting 2 Answers