Search Unity

Detecting clicking on an object

Discussion in 'Scripting' started by Passero, Nov 14, 2009.

  1. Passero

    Passero

    Joined:
    Oct 7, 2009
    Posts:
    63
    I am making some sort of builing game and having my first problem :)

    I have some objects on my terrain but i want to select them. How can i detect when i click on the mouse, witch object i can select? Do i have to cast a Ray from the camera and see if it's collide with the object or is their an onClick event or some sort?
     
  2. nemo1992

    nemo1992

    Joined:
    Nov 6, 2009
    Posts:
    13
    Try to reuse code of Dragrigidbody.js from Standard Assets
     
  3. defmech

    defmech

    Joined:
    Feb 24, 2007
    Posts:
    506
    dragrigidbody.js was one of the first things I looked at when I started. It's really tough to digest as a beginner :\

    You could attach a script to your objects that has an OnMouseOver function and then inside it, detect if you've clicked the mouse button.