- Home /
Public transform not showing in Inspector
I have a Public static transform in my script so i can attact the camera's transform to it. The transform needs to be static for me to access it in another script.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
//Fields
public float Health;
public static Transform CameraTransform;
public static
variable will not show up in the inspector.
Answer by Bunny83 · Apr 18, 2013 at 09:47 AM
static variables don'T belong to an instance of the class, so they aren't serialized with the class (just imagine you have two instances, which one would be the right one?).
The usual way to access other classes is to obtain a reference to it. Either by reference the object via public variables, using Unity's FindXXX methods or if there should be only one instance of the class, make it a singleton. I've written a handy base class which turns your class into a singleton.
With this class you can simply declare a class like this:
public class GameManager : MonoBehaviourSingleton<GameManager>
{
public Transform CameraTransform;
}
There should be only one of those classes in your scene. To access it from other scripts use:
GameManager.Instance.CameraTransform
Your answer
![](https://koobas.hobune.stream/wayback/20220613100539im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make user change variable only by specific number 1 Answer
How do I assign script as a variable in the inspector? 1 Answer
Make inspector show changes of class variable value in function? 1 Answer
Accessing an arbitary float defined via the inspector 2 Answers
How can I create variables for each materials to show in inspector (Using Editor) ? 0 Answers