instantiate prefab unity 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;
void Start()
{
Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Example 3: unity instantiate
clone = Instantiate(original);
clone = Instantiate(original, new Vector3(0, 0, 0), Quaternion.identity, cloneParent.transform);
Example 4: instantiate prefab
Instantiate(tree, new Vector3(0, 0, 0), Quaternion.identity);
Example 5: unity instantiate prefab
Instantiate(cube, Vector3 (x, y, 0), Quaternion.identity);
Example 6: unity instantiate vector3
using UnityEngine;
{
{
if (Input.GetButtonDown("Fire1"))
{
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
}
}
}