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);
}
}
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 … ?
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;
}
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 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.