Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Make a 3D mesh as a box a button

Discussion in 'Scripting' started by rimiki, Sep 30, 2015.

  1. rimiki

    rimiki

    Joined:
    Dec 30, 2014
    Posts:
    102
    Dears,

    Is it possible that I ake a 3D mesh (a box for example) a button?

    Thank you for any suggestions : ))
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Sort of, you can't just attach a button script to it and have it be ready. You'll have to write a script yourself that can check when you click the 3D mesh and call any functions you want it to.

    To check if the mesh is clicked on, put a 3D collider on the object and use Physics.Raycast() on a ray that you get from camera.ScreenPointToRay(). I recommend not using a mesh collider unless you really need the precision.

    Let me know if/where you get stuck and I'll elaborate. Best of luck!
     
  3. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,772
  4. rimiki

    rimiki

    Joined:
    Dec 30, 2014
    Posts:
    102
    Thank you :)