Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Bullet : MonoBehaviour {
- public float speed;
- public Rigidbody2D rb;
- private Vector2 direction;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- }
- private void FixedUpdate()
- {
- rb.velocity = direction * speed;
- }
- private void OnBecameInvisible()
- {
- Destroy(gameObject);
- }
- public void Initialize(Vector2 direction)
- {
- this.direction = direction;
- }
- public void OnCollisionEnter2D(Collision2D collision)
- {
- if (collision.gameObject.tag.Equals("Enemy"))
- {
- Destroy(gameObject);
- Debug.Log("Bullet has been destroyed");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement