Created a variable in the superclass, assigned to itAudioSourse
in the inspector.
[Serialize field] private
In a child class, I'm trying to use a variable likeAudioSourse
but requires you to drag the componentAudioSourse
to the object to which the child script is attached.
What to write so that it inheritsAudioSourse
from superclass?
apparently the field shouldn't be private, shouldn't it?
Алексей Шиманский2022-01-01 19:57:09No, he simply does not understand the meaning of the word class instance and thinks that if he serialized a field in a superclass instance, it must have the same reference for all descendant instances (as would be the case with a static one). I literally messed up everything that is possible and that's a mess in my head.
Yaroslav2022-01-01 19:57:09What you assigned in the inspector belongs only to this instance of the component. The inheritor cannot use the private fields of the base class in any way. What to do? Learn the basics of the language!
Yaroslav2022-01-01 19:57:09- c# : Unity | Can't add getting coins for watching rewarded ads
- c# : KeyNotFoundException: The given key was not present in the dictionary
- c# : The Strategy pattern in Unity. How to fit the logic of click-to-move motion into this pattern?
- c# : Overlay background on top of each other
- c# : Incorrect Unity3D motion calculation
- c# : InvalidCastException: Specified cast is not valid
- c# : How do I get a component in Unity through a string variable?
- c# : Is it correct to write logic in scriptableObject?
- c# : How to walk both up and down?
Just wondering: what is a superclass? Base class?
aepot2022-01-01 19:57:09