I am not entirely sure the goal of your code, but I can offer a little guidance, and can edit my answer when I know more about your issue.
Nothing is wrong with your spawning, the issue most likely has to do with your movement. Another issue is your rotation is being multiplied as a local variable, so each laser will be pointing in the same direction.
// my laser object
[SerializeField] private GameObject projectile = null;
private void Update()
{
// when I hit space, spawn new lasers
if (Input.GetKeyDown(KeyCode.Space))
SpawnLaser();
}
void SpawnLaser()
{
// keep the rotation outside of the loop so the *= 90 will change the angle the object is positioned to look at
var rotation = transform.rotation;
// as the angle is *= 90, there are only 4 possible rotations, so I would adjust your loop or rotation product
for (int j = 0; j < 4; j++)
{
Vector3 pos = transform.position;
rotation *= Quaternion.Euler(0, 90, 0);
// I attached a rigidbody to move the objects, if your objects or your player do not have rigidbodies, then they will not collide
Rigidbody laserObj = Instantiate(projectile, pos, rotation).GetComponent<Rigidbody>();
// I am adding a force of 10 in the forward direction of my newly spawned laser
laserObj.AddForce(laserObj.transform.forward * 10f);
}
}
Make sure to add a rigidbody component and collider component to the prefab that is spawning. Something else you will need to do is add a layer onto the lasers so they do not collide with each other. Look into Layer-based collisions. Make sure to give a layer to your laser and disable the collision with itself so it does not collide with other lasers.
As for your issue with collision, there are many reasons so instead of listing them here, I'll link to an answer that goes over the possible reason.
Edit: After more information given this might be closer to what you are trying to achieve.
// this script is on the object that will be firing the laser, a turret, gun, etc.
[SerializeField] private GameObject projectile = null; // laser prefab
[SerializeField] private Transform playerObjectPos = null; // reference to what we are trying to aim at (player, enemy, etc.)
private float laserFiringForce = 10f;
private void Update()
{
// when I hit space, spawn new laser spawns
if (Input.GetKeyDown(KeyCode.Space))
SpawnLaser(playerObjectPos);
}
/// <summary>
/// Spawns a laser aiming at a specified target
/// </summary>
/// <param name="target"></param>
void SpawnLaser(in Transform target)
{
// lock our rotation to only Y-axis
Vector3 targetPosition = new Vector3(target.position.x, transform.position.y, target.position.z);
// have our turret / player / etc. look at the target position
transform.LookAt(targetPosition);
// instantiate a laser at the position of our turret / player and have its rotation aim in the same direction as our turret / player
// while grabbing the reference to the rigidbody component on the laser so we can add a force to it (Note: You can have the movement logic on the laser itself instead of doing it here)
Rigidbody laserObj = Instantiate(projectile, transform.position, Quaternion.LookRotation(transform.forward, Vector3.up)).GetComponent<Rigidbody>();
// add a force in the direction the laser is facing so it moves
laserObj.AddForce(laserObj.transform.forward * laserFiringForce);
}
I would look into a tutorial you can follow for an FPS or 3D Turret game. Given the questions I would think you are newer to either programming, Unity or both. If this is one of your first projects, look into a tutorial, create it and change it to be more yours. After a few tutorials completed you should have a better understanding of Unity. If you are new to programming all together, I would also consider looking into classes, documentation, etc. of both c# and programming in general.
To get you started in Unity, try Brackey's. The tutorial I linked is his episode 4 of a 3D tower defense game where he goes over making the turrets.