Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity create 3d object in script

//You need to create the object you whant to spawn and then drag it to your assets. This will create a prefab.
//to the script part
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawn : MonoBehaviour
{
//here we declare a variable wich in it is stored our prefab (you need to drag it there in the inspection menu in unity)
    public GameObject prefabtospawn;
    void Start(){
        //now we will spawn our prefab and store it in a variable caled clone
        Clone = Instantiate(prefabtospawn, gameObject.transform.localPosition, Quaternion.identity) as GameObject;
    }
}
 
PREVIOUS NEXT
Tagged: #unity #create #object #script
ADD COMMENT
Topic
Name
8+8 =