Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UniRx;
- using UnityEngine;
- public class Bullet : MonoBehaviour
- {
- [SerializeField] private float _speed = 10f;
- private Damager _damager;
- private Vector2 _direction;
- private Rigidbody2D _rigidbody;
- private void Awake()
- {
- _rigidbody = GetComponent<Rigidbody2D>();
- _damager = GetComponent<Damager>();
- name = $"Bullet_{GetInstanceID()}";
- }
- public void Setup(Vector2 direction, GameObject owner, int damage, Subject<GameObject> OnKill)
- {
- _direction = new Vector2(direction.x, 0);
- transform.rotation = Quaternion.Euler(0, 0, direction.x > 0 ? -90 : 90);
- _damager.Owner = owner;
- _damager.Damage = damage;
- _damager
- .OnFinalDamage
- .TakeUntilDisable(this)
- .Subscribe(health =>
- {
- OnKill.OnNext(health.Owner);
- });
- }
- private void Update()
- {
- _rigidbody.velocity = _direction * (_speed * Time.deltaTime);
- }
- }
Add Comment
Please, Sign In to add comment