Vuforia AR篇(四)— AR虚拟按钮

目录


前言

在当今互联网和移动设备普及的背景下,**增强现实(AR)**技术正迅速成为连接现实世界与数字信息的重要桥梁。AR虚拟按钮作为这一技术的创新应用,不仅提供了一种全新的用户交互方式,还极大地提高了界面的直观性和操作的便捷性。本文将介绍AR虚拟按钮的使用。


一、创建虚拟按钮

创建ARCamera和ImageTarget

导入一个带动画的模型

创建虚拟按钮

给按钮name添加名字

取消Turn Off Behaviour 脚本,显示按钮mesh Renderer组件方便测试,勾选会删除mesh Renderer组件组件

经过测试虚拟按钮的位置应在如下图所示90%以内的范围

二、创建脚本

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class VirtualButtonClick : MonoBehaviour
{

    public bool _isEffect;
  
    public GameObject death;
    public GameObject effect;

    public VirtualButtonBehaviour[] buttons;
    public virtual 
    void Awake()
    {
        _isEffect = false;
        buttons = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < buttons.Length; i++)
        {
            if (buttons[i].VirtualButtonName=="Left")
            {
  
                buttons[i].RegisterOnButtonPressed(PressLeft);
            }
            else if(buttons[i].VirtualButtonName=="Right")
            {

                buttons[i].RegisterOnButtonPressed(PressRight);
            }
            else if (buttons[i].VirtualButtonName=="Effect")
            {
                buttons[i].RegisterOnButtonPressed(PressEffect);
            }

        }
    }

    private void PressLeft(VirtualButtonBehaviour obj)
    {
        death.transform.Rotate(Vector3.up,-2);

    }
    private void PressRight(VirtualButtonBehaviour obj)
    {
        death.transform.Rotate(Vector3.up,2);
    }

    private void PressEffect(VirtualButtonBehaviour obj)
    {
        _isEffect = !_isEffect;
        effect.SetActive(_isEffect);
    }

    void Start ()
    {

    }
	
    void Update ()
    {

    }
}

把脚本挂在ImageTarget上

三、效果

相关推荐
zhchyun200818 小时前
【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(05)
ui·unity·游戏引擎
_ZHOURUI_H_1 天前
不做完整 ECS,只优化数据布局:Unity EasyECS 到底是什么
unity·性能优化·游戏引擎
CDN3601 天前
360CDN发布元宇宙与VR/AR加速方案:边缘渲染与超低延迟流媒体,彻底终结眩晕感
ar·vr·cdn加速·cdn防御
郝学胜-神的一滴2 天前
Horse3D 游戏引擎研发笔记(七):Clydesdale——从流式日志到多输出订阅
c++·qt·unity·游戏引擎·图形渲染·unreal engine·opengl
小贺儿开发3 天前
Unity 程序员编曲花絮:汪峰《河流》细节修复
科技·学习·unity·程序员·音乐·demo·写代码
598866753@qq.com3 天前
Unity UniText笔记
unity·unitext
鼎艺创新科技3 天前
不依赖 UE/Unity:我们如何从零搭建一套国产三维 GIS 渲染引擎
人工智能·算法·unity·游戏引擎·三维电子沙盘
huihui3613 天前
校友网管理软件技术选型框架:基于功能核验与系统架构的量化评估
unity·系统架构·游戏引擎
五仁烧饼3 天前
Unity性能优化系列设置篇 - URP 移动端设置基线与分档策略
unity·游戏引擎
新手unity自用笔记4 天前
unity基于Socket的网络学习
网络·网络协议·学习·unity·c#·游戏引擎