Hi,
So I need to just clone my player once and that’s pretty much it. What I am trying to do is duplicate/clone my player using Instantiate. Here is what I have figured out so far.
if(Input.GetKey(KeyCode.D))
{
Instantiate(Player, new Vector3(?, ?, ?), Quaternion.Identity));
}
The main problem I am having with this script is that what should I put for my x, y, z to make the player clone itself wherever it is on the map, Right now it is going to specific coordinates and is performing the actions there. Also the player clones itself over 266 times. It just ends up crashing the system. Thank you in advance for suggestions. I have a project in school for this so fast answers are certainly appreciated and I am only 13 so please I really have tried to understand things from the API and tutorials but I just need some suggestions not rejections.
I am going to assume that this
`if(Input.GetKey(KeyCode.D)) { Instantiate(Player, new Vector3(?, ?, ?), Quaternion.Identity));
}`
is on the player.
If it is, this is how you get the players position
if(Input.GetKey(KeyCode.D)) { Instantiate(Player, transform.position, Quaternion.Identity)); }
Alternatively,
if(Input.GetKey(KeyCode.D)) { Instantiate(Player, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.Identity)); }
Also, Input.GetKey is true every frame the key is pressed for. Amend this to Input.GetKeyDown. This is only true on the frame the key is pressed, this will give you one clone.
Hope this has helped.
The way you have it now will keep instantiate your character while you are holding the D key.
Are you perhaps running this line of code in Update()? If so, you are creating 1 clone per frame, thus crashing Unity.