Answers for "unity create 3d object in script"

C#
0

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;
    }
}
Posted by: Guest on April-19-2022

C# Answers by Framework

Browse Popular Code Answers by Language