Instantiate spawn problem
Hey guys, I have a really strange problem. I need to spawn one object, after clicking on other object. I have 3 different objects, that spawns 3 different new objects, using this code: But when i click on one of these objects, it's spawns all 3 objects. And when i click on a spawned objects, they are also spawns themselves. You can see the result of only one click:
I need a help. I want, when clicked, only one object spawns and that copies can not spawn themselves. Thanks for help
Answer by Tsaras · Mar 23, 2019 at 01:55 PM
The reason the cloned objects are also cloning themselves is because they also clone this script that you posted. If you want to avoid this you have a couple options: 1) Instantiate clones and disable the script component that is responsible for this:
GameObject clone = Instantiate(Obj, new Vector3(0,0,0), Quaternion.Identity);
ClickToSpawn script = clone.GetComponent<ClickToSpawn>();
script.enabled = false;
2) Make a prefab for the clones without the script and have the originals be an object with the script.
Your answer
Follow this Question
Related Questions
Move enemy to a specific movepoint with an array (C#) 1 Answer
Spawn enemies so they aren't instantiated on top of each other (C#) 2 Answers
Spawn a random object on more than one position 1 Answer
How can I make an object clone in the time that I indicate it to appear? 0 Answers
Problem with Instantiated clones 1 Answer