unity new object code example

Example 1: Unity C# instantiate prefab

Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);

Example 2: unity create gameobject from prefab in script

using UnityEngine;

public class example : MonoBehaviour
{
	public GameObject prefab;
    
	// Start is called before the first frame update
	void Start()
	{
		Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity);
	}
}

Example 3: unity create gameobject

// Use 'new GameObject' to create a new GameObject in the current scene
SpawnedObject = new GameObject("Created GameObject");