Search Unity

GUI related issue

Discussion in '2D' started by DarkRoom, May 29, 2014.

  1. DarkRoom

    DarkRoom

    Joined:
    May 29, 2014
    Posts:
    1
    Hey, as a designer, I am pretty new to coding in unity and I decided to make a game on my own to learn javascript.The biggest problem I have now is that the GUI from every "PlacementPoint" is overlapping, only the one in the foreground being usable. Is there a way I can set all my game objects to respond to only one GUI button?
    Here's the code:

    Code (csharp):
    1. #pragma strict
    2.  
    3. var selectedMaterial;
    4.  
    5. var material_wood : GameObject;
    6. var material_enforcedWood : GameObject;
    7.  
    8. var defaultSize : Vector2;
    9.  
    10. function Start ()
    11. {
    12.     defaultSize = transform.localScale;
    13. }
    14.  
    15. function OnGUI ()                      //Here is my problem I think
    16. {
    17.     if(GUI.Button(Rect(10, 10, 100, 100), "Wood"))
    18.     {    
    19.         selectedMaterial = material_wood;
    20.         Debug.Log("Wood selecter");
    21.     }
    22.        
    23.     if(GUI.Button(Rect(115, 10, 105, 100), "Enforced Wood"))
    24.     {
    25.         selectedMaterial = material_enforcedWood;
    26.         Debug.Log("Enforced wood selected");
    27.     }
    28. }
    29.  
    30. function OnMouseOver ()
    31. {
    32.     transform.localScale = Vector2 (1.5, 1.5);
    33.     if(Input.GetButtonDown("Fire1"))
    34.     {
    35.         Instantiate(selectedMaterial, transform.position + Vector3(0,0,-0.5) , transform.rotation);
    36.     }
    37. }
    38.  
    39. function OnMouseExit ()
    40. {
    41.     transform.localScale = defaultSize;
    42. }
    43.  
    Thanks in advance.