Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

--best practice-- wats correct way of creating a button

Discussion in 'Immediate Mode GUI (IMGUI)' started by frigorifico, Jan 31, 2014.

  1. frigorifico

    frigorifico

    Joined:
    Sep 5, 2013
    Posts:
    37
    hi all,

    i was talking to a couple of friends and we started to discuss which was best.
    Create a GUI.button on the OnGUI() metod
    Code (csharp):
    1.  
    2. void OnGUI()
    3. {
    4. if(GUI.Button(new rect(),"blabla"))
    5. {
    6. }
    7. }
    8.  
    9.  
    or create a GUI Texture (a game object) put a riggid body on it and use the Update() metod whit the input.touches to se if its pressed?
    Code (csharp):
    1.  
    2. void Update()
    3. {
    4. if(input.touches >0)
    5. {
    6.       if (hit.rigidbody)
    7. }
    8. }
    9.  
    thx all
     
  2. RoryScanlan

    RoryScanlan

    Joined:
    Jan 25, 2014
    Posts:
    139
    in my opion
    Code (csharp):
    1. void Update()
    2.  
    3. {
    4.  
    5. if(input.touches >0)
    6.  
    7. {
    8.  
    9.       if (hit.rigidbody)
    10.  
    11. }
    12.  
    13. }
    will take more over head, but im a newbie scriptor :p
     
  3. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    This depends on your target platform. OnGUI doesn't work well on mobile devices, espesially if you want to support multitouch. But on other hand you don't have to have a game objects with rigidbody for each UI item.