Search Unity

Select a Building with mouse to get a small window with some text and an Image

Discussion in 'Editor & General Support' started by ansiaries, Oct 13, 2014.

  1. ansiaries

    ansiaries

    Joined:
    Jul 22, 2014
    Posts:
    22
    Hello
    i am totally new to Unity and also have not much idea with C# and JS. but the thing i have to do is

    I have an area with many buildings. I have a player from unity assets which walks around building.
    when i select a building, the building become highlighted and a small window appears with some text and image

    i read about GetMouseButtonDown and Raycast but do not know how to use them correctly
     
  2. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    You're on the right track about GetMouseDown() and Raycast, but refer to Unity documentation. Get MouseDown() is a function. It carries out all lines of code when mouse clicks the game object (note that collider is required).

    My advise is to divide your idea into small tasks. In this case it would be:

    1) Do something when mouse clicks gameobject
    2) Make gameobject change color (highlight) and go back
    3) Create GUIs or Make gameobject text visible (you can manually create a box with text in it) or Try out Unity 4.6 beta and learn about new UI
     
    ansiaries likes this.
  3. ansiaries

    ansiaries

    Joined:
    Jul 22, 2014
    Posts:
    22
    yes I am already using 4.6 beta
    the 3 tasks can be done is javascript ?
    code for all these task should be in 1 single script file?
    and the script that i made would be attached to the object to which i want to select in the game ?
     
  4. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359

    Doesn't matter what language you're using JavaScript or C#. Unity supports both equally.

    I am guessing first two tasks should be on one script. It must be attached to a building.

    Attaching script to specific object mostly does matter.
     
    ansiaries likes this.
  5. frankrs

    frankrs

    Joined:
    Aug 29, 2009
    Posts:
    300
    use OnMouseDown() if it has a collider. it automatically knows if you clicked on it or if on mobile builds if you touched it on screen
     
    elmar1028 likes this.