Question by
unityBloomingAdore · May 31 at 09:24 AM ·
how
Public variables with the same name in the same script
Hi! I have a script Consts, and I want it to display that in the Unity UI:
---------Constants.cs-----
Player's consts...
moveSpeed 5
rot Speed 6
Enemy's consts...
moveSpeed 4
rot Speed 6
----------------------------
I tried to put them in classes, then add to Consts, but it still visibly separates variables by scripts. Is there a way to keep them all in 1 script, but somehow divide (for ex. with a sctruct)?
Comment
Best Answer
Answer by unityBloomingAdore · May 31 at 10:44 AM
I solved it by serializing structs
public class Constants : MonoBehaviour
{
[Serializable]
public struct PlayerStats
{
public float moveSpeed;
public float rotationSpeed;
public float timeBetweenShots;
public float fireForce;
public int hitPoints;
public bool hasHealthPotion;
}
[SerializeField]
public PlayerStats playerStats;
and it folds in a pretty way! better than using [Header("...")]
Your answer

Follow this Question
Related Questions
Canvas problem 0 Answers
Looking at a Object for 5 Seconds then Teleport 1 Answer
how I change this C code for 2D 1 Answer
How do i rotate an object towards mouse direction? 0 Answers
how to be sure that several don't instantiate in the same spot 1 Answer