Fire projectile towards mouse position top-down 2D
So this is such a commenly asked question but no matter where i look i cant find the answer, you think for something as commen as this the answer would be everywhere. So im making a top down 2d game and would like to make a mage class where you can click and shoot a projectile towards the mouse position. Ive already got a script to make the projectile delete itself after 1 second if it doesnt hit anything. Was hoping someone could edit the script below to help, so far all it does is spawn the projectile prefab and faces towards the mouse but doesnt move, i want it to move, for the person who created the script it apparently works but not for me. So first i need it to actually move towards the mouse, next i need it to delete itself when it colides with something and id also like to be able to set where it fires from like attatching an empty object to the end of my characters staff and the projectile shoots from the end of the staff. Please help no matter where i look i cant find out how to do this
public GameObject bullet;
public float speed;
// Use this for initialization
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
Vector2 myPos = new Vector2(transform.position.x, transform.position.y + 1);
Vector2 direction = target - myPos;
direction.Normalize();
Quaternion rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg);
GameObject projectile = (GameObject)Instantiate(bullet, myPos, rotation);
GetComponent<Rigidbody2D>().velocity = direction * speed;
}
}
}