- Home /
The question is answered, right answer was accepted
How do I make an object clone itself?
I am planning to write a script on an object such that it clones itself at some point of time. I tried every possible way to do it but I am not able to. Please Help.
Answer by robertbu · Apr 03, 2014 at 09:25 PM
Just use 'Instantiate(gameObject)'. Here is a bit of script that clones when the 'A' key is pressed. Since each clone has this script, the number of objects will double each time...2,4,8,16,32...
#pragma strict
function Update() {
if (Input.GetKeyDown(KeyCode.A)) {
Instantiate(gameObject);
}
}
Follow this Question
Related Questions
How can I get the x position for the left(and right) of the screen? 2 Answers
How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 1 Answer
Object reference not set to an instance of an object 1 Answer
What can I do to make the objects I instantiated move with the background? 1 Answer
Clone Selector 1 Answer