dont instantiate clones

hey, im making a game, i want it so when the player hits a box a plane pears somehow and the player is destroyed so the plane turns into the player, but several problems hapened:

  • when the player colides with the box nothing hapens

  • when the plane is created and the player is destroyed, the plane wont move or use anny physics though it has a rigid body. so here is the code

    var player : String;
     var ObjectToDeploy : GameObject;
     var bullit : GameObject;
     var deploy = false;

    function Update ()

    if (deploy)

    Instantiate(ObjectToDeploy, Vector3(transform.position.x, transform.position.y + 10, transform.position.z), transform.rotation);

     deploy = false;
     Destroy (gameObject);
     Destroy (GameObject.Find("Player"));

    function OnTriggerEnter (hit : Collider){

    if (hit.gameObject.tag == player){

    deploy = true;



so plz let me know what can i do or some way to optimize it

For the plane, make sure you add the Move script to the objectToDeploy s gameObject.

Does your player string match the players tag, thats something to check (make sure its not empty also).

No reason to deploy to false since you destroy this GO anyway. You could also optimize that like this(get rid of deploy boolean and just call Deploy()

function OnTriggerEnter (hit : Collider)
    if (hit.tag == player)

function Deploy(myPlayer:GameObject)
     var dObj=Instantiate(ObjectToDeploy, Vector3(transform.position.x,
         transform.position.y + 10, transform.position.z), transform.rotation)as GameObject;

     //add other components
     dObj.tag==player;//change tag if necessary

     Destroy (myPlayer);
     Destroy (gameObject); //Call this 2nd, otherwise this script is already gone