Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Projectile : MonoBehaviour
- {
- [SerializeField] private Rigidbody _rigidbody;
- [SerializeField] private float _speed = 100;
- [SerializeField] private float _lifeTime = 10f;
- private Vector3 _direction;
- public Action<GameObject> TargetDetected;
- private void Awake() =>
- Destroy(gameObject, _lifeTime); // Лучше использовать пул объектов
- public void Throw(Vector3 direction) =>
- _direction = direction;
- public void Stop() =>
- _direction = Vector3.zero;
- private void FixedUpdate() =>
- _rigidbody.velocity = _direction * _speed;
- private void OnCollisionEnter(Collision collision)
- {
- TargetDetected?.Invoke(collision.gameObject);
- Destroy(gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement