I am trying to make a bullet fly in the direction the mouse is located in relation to the player character.
What I have so far:
public class BulletMove : MonoBehaviour
{
public Rigidbody2D bullet = null;
private float speed = 5f;
void Update()
{
if (Input.GetButton ("Fire1"))
{
Rigidbody2D shot = Instantiate(bullet,
transform.position,
transform.rotation) as Rigidbody2D;
shot.velocity = new Vector2(-1, 0);
}
}
}
This shot.velocity = new Vector2(-1, 0); makes me able to shoot to the left only as its hardcoded numbers but how do I get the position of the mouse to act as direction to shoot?