Search Unity

Where to put my OnMouseDown() to react to click on terrain?

Discussion in 'Scripting' started by IngeJones, Nov 28, 2015.

  1. IngeJones

    IngeJones

    Joined:
    Dec 11, 2013
    Posts:
    129
    I want to do something when I click on the terrain, and that something needs to use the coordinates of the RayCastHit. Usually if I want to tell if I have clicked something, I put OnMouseDown() eventhandler on the object's own script. Unfortunately Unity won't let me make a script called terrain, as it apparently already exists, so where should I put it instead?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Anything attached to the terrain GameObject should work
     
    IngeJones likes this.
  3. IngeJones

    IngeJones

    Joined:
    Dec 11, 2013
    Posts:
    129
    So you mean simply attach an extra script component to terrain, with a different class name, and put the mouse trap on there?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860