Code Converstion into javascript Help?

Hello everyone. My friend is helping me make a sidescrolling 2d shooter that runs off of the y and x axis. He doesn’t use unity so he wrote some script down and I was wondering if someone could help me convert it to unity javascript and also tell me if it would work for shooting to the mouse. Here is his code:

mPos = vector3; (mouse position)
pPos = vector3; (player position)
bPos = vector3; (Bullet position)

xdir = mPos.x - pPos.x;
ydir = mPos.y - pPos.y;

angle = Atan2(xdir,ydir);

lx = cos(angle);
ly = sin(angle);

bPos.x += bulletMoveSpeed * lx * Time.deltaTime; 
bPos.y += bulletMoveSpeed * ly * Time.deltaTime;

I hope this code will work because shooting in 2d has given me countless problems.

You need to put all that inside a function called Update(). Here is some things you’ll need. Input.mousePosition, Camera.ScreenPointTo, Transform.position, Mathf.Atan.

This is not a translation of you code but it is code that should work… I am rather bored and should be revising so this was a more entertaining alternative. Hopefully it works though I haven’t tested it and as I don’t know how your game is set up I don’t know if it will be relevant but here you go:

var GunObj : Transform; //the gun
var MouseWorldPos : Vector3; //a variable to store position of cursor
var Bullet : GameObject; //bullet/projectile to be fired
var ROF : float = 0.5; //Rate Of Fire of your gun

function Update() {
	MouseWorldPos = camera.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, GunObj.position.z));
	if(Input.GetButton ("Fire1")){
		InvokeRepeating("Shoot", 0/*start firing imediately (no delay)*/, ROF); //start calling the Shoot function

function Shoot() {
	Instantiate(Bullet, GunObj.position, GunObj.rotation); //creates a new 'bullet' every time this function is called