Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Bullet : MonoBehaviour
- {
- [SerializeField] private float _percentDamage = 25;
- [SerializeField] private float _lifeTime = 5f;
- [SerializeField] private float _moveSpeed = 3f;
- [SerializeField] private Rigidbody _rigidbody;
- private void Start()
- {
- Destroy(gameObject, _lifeTime);
- }
- public void Setup(Vector3 direction)
- {
- _rigidbody.velocity = direction * _moveSpeed;
- }
- private void OnTriggerEnter(Collider other)
- {
- if (!other.CompareTag("Player") && other.TryGetComponent(out IDamageable damageable))
- {
- damageable.GetDamage(_percentDamage);
- Stop();
- Destroy(gameObject);
- }
- }
- private void Stop()
- {
- _rigidbody.velocity = Vector3.zero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement