Search Unity

Swapping meshes

Discussion in 'Scripting' started by nebulousecho, Mar 28, 2008.

  1. nebulousecho

    nebulousecho

    Joined:
    Jan 23, 2008
    Posts:
    23
    I have a menu set up that lets the player choose a location, and I want it to display a mesh of the country based on the current selection. What I want to ask is what would be the most efficient way to replace the mesh for each choice?

    I hope this is clear.. :roll:

    For example:

    Choice one shows a mesh of Japan, replaces Germany or USA mesh.
    Choice two shows a mesh of the United States, replaces Japan or Germany mesh.
    Choice three shows a mesh of Germany, replaces USA or Japan mesh.

    My idea was to start with an empty and swap that with a country mesh. Maybe I'm missing it but I'm not seeing anything in the documentation about how to replace an object with another.

    Here's my (currently bare bones) menu code:

    Code (csharp):
    1. var arenaselection = 0;
    2. var AS;
    3. var arenaselectiontext = "Select";
    4.  
    5. arenaselection = PlayerPrefs.GetFloat("ArenaSelection", AS);
    6. return arenaselection;
    7.  
    8. function OnGUI () {
    9.    
    10.     GUI.Label (Rect (30,460,125,20), "Choose an Arena");
    11.     GUI.Label (Rect (30,480,150,20), arenaselectiontext, "box");   
    12.    
    13.     if (GUI.Button (Rect (30,480,25,20), "<")) {
    14.    
    15.     arenaselection = (arenaselection - 1);
    16.    
    17.         if (arenaselection == 0) {
    18.             arenaselection = 1;
    19.         }
    20.     }
    21.  
    22.     if (GUI.Button (Rect (155,480,25,20), ">")) {
    23.    
    24.     arenaselection = (arenaselection + 1);
    25.    
    26.         if (arenaselection == 2) {
    27.             arenaselection = 1;
    28.         }
    29.     }
    30.  
    31.     if (arenaselection == 1) {
    32.        
    33.         arenaselectiontext = "Japanese Budokan Hall";
    34.    
    35.     }
    36.  
    37. }
    38.        
    39. function Update () {
    40.     PlayerPrefs.SetFloat("ArenaSelection", arenaselection);
    41.    
    42. }
    Thanks for any help!