Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Weapon : MonoBehaviour
- {
- [SerializeField] private ShootType _shootType;
- public void Init(WeaponConfig weaponConfig)
- {
- if (_shootType != null)
- {
- throw new ArgumentException();
- }
- _shootType = weaponConfig.GetShootType();
- }
- }
- public abstract class ShootType
- {
- public abstract void Shoot();
- }
- public class WeaponConfig
- {
- [SerializeField] private ShootType _shootType;
- public ShootType GetShootType()
- {
- return _shootType;
- }
- }
- public class WeaponSpawner : MonoBehaviour
- {
- [SerializeField] private Weapon _weapon;
- public Weapon CreateWeapon(WeaponConfig weaponConfig)
- {
- var newWeapon = Instantiate(_weapon);
- newWeapon.Init(weaponConfig);
- return newWeapon;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement