Question by
equeomaninho420 · Oct 25, 2020 at 03:34 PM ·
instantiateprefablevel editorlevel-editor
Spawning Prefab not working correctly
I'm making a level editor and I need help spawning prefabs. Below is the prefab that i'm using. Now, the code that I'm using makes it so when I click one of those orbs, a new Prefab is spawned in that diretion, and then disable the orb. And it kinda works:
Code for spawning:
void OnMouseDown()
{
Instantiate(prefab, transform.position + transform.forward, transform.rotation);
gameObject.SetActive(false);
}
Note: I did try to use PrefabUtility.InstantiatePrefab, but that didn't spawn anything:
void OnMouseDown()
{
GameObject currentTile = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
currentTile.transform.position = gameObject.transform.position + gameObject.transform.forward;
gameObject.SetActive(false);
}
How do I pull this off?
Comment
Your answer
Follow this Question
Related Questions
Changing rotation of prefab 0 Answers
Saving Instantiated objects,Saving Instantiated objects 0 Answers
Instantiating prefabs, and making them move. (Projectiles) 0 Answers
Find instantiated prefab by name 3 Answers
Arrows fire in reverse. 1 Answer