Need urgent help to create projectile shooting script with raycasting

I want to shoot projectiles randomly from one of modules every 1-2 seconds (time between bullets decreases as game goes on). The objective of the game is to have the player dodge the bullets. I have mainly finished my player movement script, but I am stuck on how to get the projectiles to shoot straight (currently they just fly up into the air turning and twisting) and from different positions (each position will represent a different turret firing - ex: (1,0,10) is position of turret one and (5, 0, 10) is position of second turret). Right now the bullets fire very fast and flying all over the place instead in a straight line. I was thinking of using raycasting to detect if the player has been hit. Also I was thinking of using raycasting to measure the distance of the bullet from the turret so the script knows when to fire the next bullet (I only want one bullet in the scene at a time). Currently I have a random number generator to pick which module (basically position) to fire the bullet from. Here is my code (very incomplete – just looking for some tips and basic structure):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserShooter : MonoBehaviour {

private int modChoose;
public GameObject projectile;
	//Defining variables...
void Start () {
	modChoose = Random.Range (1, 4);
	//modChoose is picking which module to shoot from. In this case, the module is basically a position where the bullet should start.
}

void Update () {
	if (modChoose == 1) {
	GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
	bullet.GetComponent<Rigidbody>().AddForce(transform.forward * 10);
	}
	//If the first module is picked, fire a bullet at a specific start pos (still havent added the start pos script though) etc.
	if (modChoose == 2) {
	GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
	bullet.GetComponent<Rigidbody>().AddForce(transform.forward * 10);
	}
	if (modChoose == 3) {
	GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject;
	bullet.GetComponent<Rigidbody>().AddForce(transform.forward * 10);
	}
}
				
} 

Thanks for help :slight_smile:

You can euler to rotate the projectile at spawn