Search Unity

Adding click and drag to GUIText object...

Discussion in 'Scripting' started by jeremyace, Feb 19, 2006.

  1. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I would like to add click-and-drag to one of my GUIText scripts but I can't figure it out. I create the GUIText object from a central controller script, so it's not as easy as an OnMouseDown event.

    I have the script to move the GUI with the mouse when the mouse button is held down, but I can't figure out how to only move the GUI if the user clicked ON the main GUI. As far as I can see this has to do with raycasting but I can't figure it out because the dragging script is also on the central controller and not the actual GUI object. How would I go about this?

    Hope that description wasn't too convoluted. ;)

    Thanks guys,
    -Jeremy
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Why not? Can't you just add another script using AddComponent when creating the guitext?

    If you don't want that you can use the HitTest function:
    http://www.otee.dk/Documentation/ScriptReference/GUIElement.html
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Thanks Joe. I actually forgot you could also attach scripts with the add component method, but that's not what I wanted anyway. I want to keep as much of this in a single script as possible so HitTest is just what I needed.

    Thanks,
    -Jeremy