How to make a VR Button | Unity Tutorial
ฝัง
- เผยแพร่เมื่อ 7 ม.ค. 2025
- Accelerate your development process with our new, ready to use VR UI PACKAGE, now on the Unity Asset Store! Link for %10 off: assetstore.uni...
In this video I will teach you how to make a button for VR using Unity. You can use this button to execute any function that you'd like in Unity. I will be testing this button on the Oculus Quest 2.
COURSE PLAYLIST: • VR Development Full Co...
Thanks for watching!
Please keep making these! They’re so helpful!
Glad you find them helpful, thanks for the feedback!
can i also make the button spawn a specific something?
This will be helpful for my fangame!
Hello, great video. One small problem. It's not registering the exit event, why do you think that is? I can't manage to fix it. Help greatly appreciated.
Hello, does your button can work with any hand system ? or it need to be YOUR system ? cheers
Hi,
I am quite new to the VR and just started. I followed the tutorial fully but the spawned sphere passes through the floor. I checked the collider setup, collision detection by adding it to the rigidbody in the sphere but nothing is working. Any body facing similar problems or solved this kind of problem?
My Sphere is falling through the ground in VR but works in Unity Editor, What to do?
Thanks for the help! Good tutorial.
Thanks Pawel!
Do you know how can I stop playing the sound when I push another button (which is the same one with this one)? So there are two buttons, one for playing and the other for pausing or stop. I am struggling out the script with it
Hiya, love this tutorial!!
I am having an issue with the Press, after it is used once the object disappears, but the function remains? Any idea what may be causing this? Thanks
any solution?
@@ashfaqmuhammed8135 Increase the height of press gameobject. its probably smaller then the transform position of the button which on press will move inside the base and will seem as if it has dissappeared. hope it helps.
Increase the height of press gameobject. its probably smaller then the transform position of the button which on press will move inside the base and will seem as if it has dissappeared. hope it helps.
how do i get the sphere function to run ONLY when i press the button? currently when you press play it automatically runs the function.
Cool! Nice tutorial. Simple, clean, and effective.
Thank you!
the ontrigger enter and exit executes both once per frame when my hands are inside the collider
Hey! Can you please make a video on how to make a working gun, or a dummy. Love your vids!
Thanks! Yes, it will be coming out soon!
I am getting a error ( virtual button can not be created INVALID_AREA) while creating virtual button, can you please tell me what should I do to solve this error .
Can you make this work with using only Ray interactor?
HI i'm wondering why my script doesn't have the Events area when i use this same script. thanks - nice tutorial
oh.. after restart it seems events worked. I did have to delete the "Invoke" section as unity wouldn't play with in there
@@AhimsaCreative Glad it worked! Sometimes you need to minimize Unity and then open it so the code compiles and the events show in the inspector. Otherwise, the scripts should work as is and Invoke should work so you probably have another problem.
The collusion happened only when I move my body towards the button but the my hands not working, can you show us your hand Rigidbody settings
Should work if your hands have any collider on them.
no need for rigibody. If anything that's more likely to mess with your hands. Just make sure they have a collider on them.
How to make it prevent from spamming?
Great tutorial! works as expected. I couldnt make it work with any other OVR rig though, it only works with the CustomHands with the OVR grabber in it. Even if I use other hands and copy the children of the CustomHands (the ones that come in the oculus integration pack, the ones you also use in the video) it doesnt work, it only works with the CustomHands. Does anyone have any idea why
any luck?
@@josh879879 Hey, Not sure if you already fixed it or not, but for me personally the issue was with the Mesh Collider. Make sure in the Mesh Collider component, make sure beside "Mesh" the box is filled with the object's mesh, because mine was set to none by default.
@@R3troBlue Thanks alot Retro!!
The reason you're not making is about pushing the button but just passing the finger on it, is it about performances ?
Hi, you could definitely make it to be pushed and be more physics based. I made it this way to keep it simple!
can you give the script ?
Hi!, would this work if I were to attach the button to a controller?
Yes, I have tried that before and it worked. Just put it under one of the hand anchors.
when i press the button it just stays down
Same issue for me
@@gremlinfrend just increase the height of the press this might help.
just increase the height of the press this might help.
if(other.gameObject == presser)
Sound link?
Hi, for me is not working, when I test it, the button gets pressed as I approach it. It stays pressed even if I move away. Please help me.
Did you solve it?
@@jesusantoniogarciafusi4052 Not yet
if(other.gameObject == presser)
My hands got disappeared while changing the layer and button didn't showed up
in camera culling active the layers so you can see the objects in play mode. hope it helps.
if you can can i have the script please
Help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class ButtonVR : MonoBehaviour
{
public GameObject button;
public UnityEvent onPress;
public UnityEvent onRelease;
GameObject presser;
AudioSource sound;
bool isPressed;
// Start is called before the first frame update
void Start()
{
sound = GetComponent();
isPressed = false;
}
private void OnTriggerEnter(Collider other)
{
if (!isPressed) {
button.transform.localPosition = new Vector3 (0, 0.003f, 0);
presser = other.gameObject;
onPress.Invoke ();
sound.Play ();
isPressed = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject == presser) {
button.transform.localPosition = new Vector3(0, 0.05f, 0);
onRelease.Invoke ();
isPressed=false;
}
}
public void SpawnSphere()
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
sphere.transform.localPosition = new Vector3(0, 1, 2);
sphere.AddComponent();
}
}
Hi,
Thank you for the script. I followed the tutorial but the spawned sphere kept falling through the floor. Can you please help?
@@khalidmubashshir8748 Try not to use gravity for the sphere
@@esmeemarch612 i tried not using the gravity but then the sphere gets stuck in the space and no other spheres are visible.
I used the script that you gave but the spheres fall right through the floor.
I'm sorry, i try to refrain from making comments but this tutorial is horrible. Spent too much time explaining useless stuff(like dude, the button model shouldn't take you 3 minutes to explain, just make it before the tutorial lol), and all the tutorial is is how to make a physical button, nothing really VR related at all. I coulda figured that out easily, my friend... And it's not really written too well in the first place, you should be checking for tags on trigger enter or the specific controller component, or anything and everything that hits the button will trigger it.
So create your own channel and explain it though. I guess you can make it really nice, good luck!!
@@diariocancun3698 I could. I used to make tutorials, actually, i removed them all because i had my ex's name in my old company's name lol
Certainly could make a 2 minute video explaining how to make a cylinder that reacts to being pressed down