My game is a 2D, top-down game where you aim with the mouse and the gun follows it. I'm trying to get the bullet to go in the direction of where the mouse is. The code will be a component of the bullet prefab. here my code:
public class BulletBehavior : MonoBehaviour {
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
}
private void OnTriggerEnter2D(Collider2D collision)
{
Destroy(gameObject);
}
}