Advertisement
Ipashilovo

Untitled

Jul 25th, 2021
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. public class Weapon : MonoBehaviour
  2. {
  3.     [SerializeField] private ShootType _shootType;
  4.  
  5.     public void Init(WeaponConfig weaponConfig)
  6.     {
  7.         if (_shootType != null)
  8.         {
  9.             throw new ArgumentException();
  10.         }
  11.         _shootType = weaponConfig.GetShootType();
  12.     }
  13. }
  14.  
  15. public abstract class ShootType
  16. {
  17.     public abstract void Shoot();
  18. }
  19.  
  20. public class WeaponConfig
  21. {
  22.     [SerializeField] private ShootType _shootType;
  23.  
  24.     public ShootType GetShootType()
  25.     {
  26.         return _shootType;
  27.     }
  28. }
  29.  
  30. public class WeaponSpawner : MonoBehaviour
  31. {
  32.     [SerializeField] private Weapon _weapon;
  33.  
  34.     public Weapon CreateWeapon(WeaponConfig weaponConfig)
  35.     {
  36.         var newWeapon = Instantiate(_weapon);
  37.         newWeapon.Init(weaponConfig);
  38.         return newWeapon;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement