Shooting at mousePosition

I’m stumped; what I’m trying to do is shoot in the direction of my mouse cursor, after searching through code; I couldn’t quite find the answer; this is my attempt:

       if (Input.GetButton ("Fire1")) {
        var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        var distance: float =14;
        var hitPoint : Vector3;
        if (Physics.Raycast (ray, distance)) {
            hitPoint = ray.GetPoint(distance);
            var direction : Vector3 = hitPoint - transform.position;
            Instantiate (enemyBullet, transform.position, transform.rotation);
            enemyBullet.transform.position =(direction * speed * Time.deltaTime);

The bullet spawns fine; but has ain’t moving; that’s where I could do with some help as I am kind of lostagain!

Thanks for any suggestions, Bobble

Your script only moves the bullet a small distance in that frame. You need to have a script attached to the bullet to make it move every frame. Such as

transform.position += direction * speed * Time.deltaTime;

Though moving a transform directly like that means it will not calculate collisions correctly. Instead, attach a rigidbody to the bullet and move using

bulletRigidbody.AddForce(direction * speed);

Check out Unity - Scripting API: Collider.OnCollisionEnter(Collision) for information about getting collision information. The line “Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.” is important for your needs.