Search Unity

button-like event script behavior for meshes?

Discussion in 'Scripting' started by diekus, Sep 23, 2014.

  1. diekus

    diekus

    Joined:
    Jan 16, 2013
    Posts:
    10
    Hi

    I want to attach to different objects one script (name something like button behavior or something like that) to mimic that when it is clicked something happens. But something different happens than when clicking another object.

    Think about a shopping site like behavour. If you want to go in a items detail you clik on it an a template page is populated with that info.

    Does it make any sense to think about this kind of implementation, am I kinda trying to force the event model on a game loop?

    Any ideas?

    Cheers!

    --diekus
     
  2. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    Yeah it is possible.
    You can use a delegate in that script, and attach another script to each object that has the command you want to use.
    You can also use an interface for that.

    But if that's advanced for you, just create one script with many functions (if gameobject is this, do that, else, do that) or many similar scripts, one for each object.