Question by
hellfreezes · Feb 15, 2017 at 02:15 PM ·
c#getcomponentpolymorphism
How can i get component as an abstract base class?
I have an abstract class Ammo : MonoBehaviour. And several subclasses: class YellowLaser : Ammo and class Bullet : Ammo. YellowLaser or Bullet added as a component to GameObject "Piu" at the scene. I have a GameObject "Player" with a script component. Player have to get Piu ammo component from it's script. Player did't know a subclass of Ammo that added to Piu (YellowLaser or Bullet). So Player have to get a base Ammo component to work with. piu.GetComponent() did't work of course. How can I get a base component Ammo?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612111137im_/https://answers.unity.com/themes/thub/images/avi.jpg)