Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
74 views
in Technique[技术] by (71.8m points)

c# - Change object [SerializeField] for another with script

Is possible to change a object [SerializeField] for another with script? I try but doesn't work good i need to change the music with controlled with slider in the scene. The script to controller:

public AudioMixer AudioMixer;
public Slider slider;

public Dropdown resolutionDropdown;

[SerializeField] AudioSource audioSrc;
public float Nvolume = 1f;

Resolution[] resolutions;

public GameObject pauseMenuOptions;
question from:https://stackoverflow.com/questions/65833527/change-object-serializefield-for-another-with-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your problem has nothing to do with SerializeField. Are you aware what SerializeField do? SerializeField in Unity used for reflecting object value to Unity Editor Inspector. It doesn't affect variable protection level. When you didn't assign any protection accessors (private, public, internal), it is private as default. So only accesible in this class level. If you want to access it from another class, you should just add public accessor.

public AudioSource audioSrc; 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...