2019-09-17 20:45:08 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
2019-09-17 15:43:40 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Bullet : MonoBehaviour
|
|
|
|
|
{
|
2019-09-17 20:45:08 +02:00
|
|
|
|
[SerializeField] private int _damage;
|
|
|
|
|
public int Damage => _damage;
|
|
|
|
|
|
|
|
|
|
// Speed in m/s
|
|
|
|
|
[SerializeField] private float _speed;
|
|
|
|
|
public float Speed
|
2019-09-17 15:43:40 +02:00
|
|
|
|
{
|
2019-09-17 20:45:08 +02:00
|
|
|
|
get { return _speed; }
|
|
|
|
|
set { _speed = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SerializeField] private Vector2 _direction;
|
|
|
|
|
public Vector2 Direction
|
|
|
|
|
{
|
|
|
|
|
get { return _direction; }
|
|
|
|
|
set { _direction = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
Mover mover = GetComponentInParent<Mover>();
|
|
|
|
|
if (mover == null)
|
|
|
|
|
{
|
|
|
|
|
throw new MissingComponentException("Missing Mover!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mover.Direction = Direction;
|
|
|
|
|
mover.MaxSpeed = Speed;
|
2019-09-17 15:43:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 20:45:08 +02:00
|
|
|
|
// Destroy on Stay, collision effects should be handled on Enter
|
|
|
|
|
private void OnCollisionStay2D(Collision2D other)
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
2019-09-19 11:38:00 +02:00
|
|
|
|
|
|
|
|
|
private void OnBecameInvisible()
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
2019-09-17 15:43:40 +02:00
|
|
|
|
}
|