- Home /
Problems with cloning, aka double trouble.
So I have an enemy with some rudimentary AI on it in addition to the pre-made unity components "Character Controller" and "Character Motor".
It is not a prefab, it is on the stage.
When I manually duplicate the object with ctrl+d it makes a second enemy that follows the same AI perfectly. However, I need my enemy to be cloned with script. Accordingly, I have a code that triggers once when I press the "C" key, here it is:
var original:GameObject = GameObject.Find("enemy");
var clone:GameObject = Instantiate(original);
clone.transform.position.y += 10;
clone.transform.position.x += 5;
And it works! There's a duplicate of my enemy that appears to have all the components of the original when I click on it's name in the editor during testing. Furthermore, if the enemy is cloned while running, the clone will be running as well so the scripts must be there.
Here's the problem: I have a function that instantiates a different prefab (an arrow above the enemies head) and changes a boolean variable to true on a key press when it's centered in the screen; however, these do nothing on the clone and the editor shows that the variable is still false even though the function is being activated.
Now's here the bizarre part, I made the function print the boolean variable upon said key press and centering and it prints "true"... it shows false in the editor but prints true during testing... :| What's going on?
Your answer
Follow this Question
Related Questions
why wont this SendMessage work 1 Answer
.sendmessage not working C# 1 Answer
Trouble with sendmessage 1 Answer
Calling a function from a instantiated clone 1 Answer
Instantiate an enemy, best way to initialize behavior variables 1 Answer