Search Unity

[SOLVED] Problem with Instantiate

Discussion in 'Scripting' started by DarkSoul, May 9, 2010.

  1. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    Hello.
    I created this code:

    Code (csharp):
    1.  
    2. if (GUI.Button(new Rect((Screen.width / 2) - 30, Screen.height - 60, 60, 60), ICO_tower1))
    3.         {
    4.             //Create tower
    5.             Object fakeTower = new GameObject();
    6.             fakeTower = Instantiate(Tower1, new Vector3(0, 0, 0), Tower1.transform.rotation);
    7.             TowerID = fakeTower.name;
    8.             ThisTower = GameObject.Find(TowerID);
    9.         }
    10.  
    My objetive is build several structures (towers) in the map, but to create another structure, the last structure returns to Vector3(0,0,0). How I repair this?
    Thanks!
     
  2. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    I had to save the last position of tower and then apply this position to the new tower.
     
  3. rsx

    rsx

    Joined:
    Nov 4, 2009
    Posts:
    87
    How is this true?
    Code (csharp):
    1. TowerID = fakeTower.name
    Isn't there a real instance ID you could use? In Unity, you can have multiple objects with the same name in the scene, right?

    Maybe it doesn't matter, but just pointing it out in case it helps.