button on wall?

Hi all, I've been trying to find a way to have a button on a wall, but everything I've found when searching for 'button' seems to be going on about gui buttons, which I don't want.

Basically, I want to have a button on the wall, and when the player is near it and presses, say, enter, something happens.

If anyone has some info or links on how to do this, it would be greatly appreciated.

EDIT: Sorry, should have been clearer. It would be nice to have the player face the button to use it if possible. For now I'm using the vector3 distance thing (with the player only having to be in range). Thanks for the input so far :-)

You need to use a combination of Input to get player input, Raycast to detect what the player is looking at (or OnCollisionEnter / OnTriggerEnter, or simple Vector3 distance), and an actual GameObject for the button. If you have more specific questions feel free to elaborate.

you can use

OnMouseOver && input(“Fire1”)

and add vector3 to not click as far the button as can see

i would recommend a simple trigger if u r supposed to activate it with a char.

for example

function OnTriggerEnter(hit:Collider){

    if(hit.gameObject.tag=="ChangingLevel" && Input.GetButtonDown("E")){
        /*press button codehere */


so when u enter the collider in that object u are able to press it . inside that if u can play animations. other functions basicly anything.

if it doesnt work perfectly or it fails sometimes u could use a flag when u enter the trigger and use an update to detect the if better.

i encourage u to read the documentation if u need more info about triggers :slight_smile:

happy coding