- Home /
Question by
ibrahimarslan · Sep 26, 2012 at 03:47 PM ·
playervariableclone
Clone new gameObject from variable
Hi I need to new gameObject from player variable. My destroy trigger and destroy my player and missing player. Don't instantiate player
var player:GameObject;
var copyPlayer:GameObject=new GameObject(player); //my problem
var playerPivot:GameObject;
function Update () {
if(Input.GetKeyDown(KeyCode.Mouse1)){
Instantiate(copyPlayer,playerPivot.transform.position,Quaternion.identity);
}
}
Comment
Answer by whydoidoit · Sep 26, 2012 at 03:49 PM
Use this instead of the object initialization you are attempting:
var copyPlayer : GameObject;
function Start()
{
copyPlayer = Instantiate(player);
}
Instantiate(copyPlayer,playerPivot.transform.position,Quaternion.identity);
Instantiate copyPlayer and go to destroy trigger. Destroy and missing copyPlayer :(
Your answer
Follow this Question
Related Questions
Clicking on a Cube. Then -1 a varible 1 Answer
clone functions 2 Answers
Passing a variable through the main menu 2 Answers
Assigning varaibles to prefabs 1 Answer
I am trying to access a variable from another script. 1 Answer