To serialize a field in unity I do this:
[SerializeField]
public int one;
[SerializeField]
public int two;
[SerializeField]
public int thee;
[SerializeField]
public int four;
Is there a way to use [SerializeField] for multiple fields? Something like this:
[SerializeFields]{
public int one;
public int two;
public int thee;
public int four;
}
Hello!
I know this is not exactly what you are looking for, but in this case you can try the following
[SerializeField]
int one, two, three, four;
[SerializeField]
string name, lastName, address, school;
Hope this helps a bit ;D
This question is old and I’m sure you’ve figured it out by now, but for anyone else looking for a solution to this, it is possible to serialize all your fields with one declaration with [System.Serializable]. Example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InspectorGadget : MonoBehaviour
{
[System.Serializable]
public class Inspection
{
public int one;
public int two;
public int three;
public int four;
private string message;
}
public Inspection inspector = new Inspection ();
public void Start ()
{
inspector.one = 1;
inspector.two = 2;
inspector.three = 3;
inspector.four = 4;
inspector.message = string.Format("{0} + {1} + {2} - {3} = {4}",
inspector.one,
inspector.two,
inspector.three,
inspector.four,
"2");
Debug.Log (inspector.message);
}
}