Search Unity

Tower Editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by Morseton, Jun 30, 2016.

  1. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    Hello, I'm trying to make a custom window to edit the towers in my game.

    Each tower has different variables. Here's how I'm initializing them:
    Code (CSharp):
    1. public class Tower : MonoBehaviour {
    2.     public struct tower_base{
    3.         public string tower_name;
    4.         public GameObject prefab;
    5.         public int metal_cost;
    6.         public int crystal_cost;
    7.     };
    8.  
    9.     public tower_base[] tower = new tower_base[0];
    10. }
    Now, on the custom window codes, I'm creating a window for each tower and a button to add a new tower.
    When I add a new tower, I add that tower to the tower_base variable from the gameobject holding the Tower script, and ofc I duplicate the array to add +1 to its size and then set the values back.


    All of this works, but when I start the game, everything goes back to zero. All the towers are lost. Why is this happening? Shouldn't it be saved since the variables are in a game object?
     
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
  3. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    Thanks, I will look into that, I had never used serialization! Time to learn :p
     
    IzzySoft likes this.