Search Unity

Hovering over an Object script and it displays a label

Discussion in 'Scripting' started by Kameron-Schwab, Oct 6, 2015.

  1. Kameron-Schwab

    Kameron-Schwab

    Joined:
    Sep 16, 2015
    Posts:
    33
    I'm working on a Horror game called Downturn and I've coded a Flashlight script but now I wanna make a script is JS or C# that when I hover over an Object it'll pop up a label in the middle of the screen saying... Press (E) to turn off Alarm. Something along that line and when he/she isn't hovering anymore it'll be removed. ​
     
  2. Kameron-Schwab

    Kameron-Schwab

    Joined:
    Sep 16, 2015
    Posts:
    33
    Also, if it's possible which it is in C# to add something like a toggle for example when hovering over the object it'll show on screen "Press (E) to turn Alarm on" & when the alarm or whatever it is and you hover on the object again it'll say "Press (E) to turn Alarm Off"
     
  3. Kameron-Schwab

    Kameron-Schwab

    Joined:
    Sep 16, 2015
    Posts:
    33
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    without knowing a lot more about your scene/project it'll be hard to provide much more than pointers...

    there is the built in:
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html
    (ignore the reference to GUIElements, that's old UI system...)

    or failing that you can look at manually coding something with raycasts
    http://docs.unity3d.com/ScriptReference/Input-mousePosition.html
    http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
    (you wont be instantiating anything but calling a function on the object that was hit to bring up the UI you want for that you'll need a raycast function which has a "out hit" parameter)

    basic UI creation is covered in the learn section https://unity3d.com/learn/tutorials/topics/user-interface-ui
     
    Kameron-Schwab likes this.
  5. Kameron-Schwab

    Kameron-Schwab

    Joined:
    Sep 16, 2015
    Posts:
    33
    Thank you I'll look into this.