Instantiate an object from the main cameras ROTATION

Hello, i’ve got a question. Is it possible to rotate a prefab when instantiating it? So it rotates in a spesific way before or exactly on time when instantiating. For example changing its x axis? Or do i have to add a script to every prefab that changes the rotation?

So for example if i want to spawn an arrow, then i use this line, and attach the script to the main camera. But in my case the arrow is rotated the wrong way, and it changes , because it spawns in different rotation, (because of my camera rotation) So i cant just change the rotation, i have to get the current rotation and change if from there but i dont know how to. My arrow is pointing vertical when i instantiate it, but i want it to point horozontaly. FROM MY MAIN CAMERA ROTATION.
Any help is welcome!

//Instantiating example:
Instantiate(arrow, spawnPos.transform.position, transform.position);

I don’t understand your problem in detail, but there are several ways to rotate an object when instantiating it and one of those should be applicable to your use:

using UnityEngine;

public class Instantiator : MonoBehaviour
{
	public GameObject prefab;
	public Transform target;

	void Start ()
	{
		InstantiateArrow();
	}
	
	public void InstantiateArrow()
	{
		// Align arrow with a Transform object in space.
		Instantiate(prefab, target.position, target.rotation);

		// Align arrow with target position, but this objects (or the camera's) rotation.
		Instantiate(prefab, target.position, this.transform.rotation);

		// Apply any custom rotation after instantation like pointing towards a target.
		var arrow = Instantiate(prefab, target.position, Quaternion.identity) as GameObject;
		arrow.transform.rotation = Quaternion.LookRotation(this.transform.forward, this.transform.up);
	}
}

Instantiate(arrow, spawnPos.transform.position, myCam.main.transform.rotation); //You may need to find your camera first

This literally spawns the object with the same rotation as the main camera. This may not be what you want but it demonstrates how easy it is to use rotation setup in Instantiate.

Use world axes to find out rotation differences between objects. For example, you can use Vector3.Angle and Dot product to find its alignment with the x axis and use this to similarly align other objects. There are examples of this around the web and coding examples are included in the Scripting Reference.

How the arrow is instantiated:


How i want it to be instantiated: