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上

三、效果

相关推荐
ar012313 天前
AR远程协助产品:重塑工业服务的未来
人工智能·ar
叶帆13 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
久数君13 天前
AI三维建模工具“造形家”:地理场景三维化的高效解决方案
unity·glb·ai算法·ai三维建模工具·地图框选·造形家·城市建筑模型
会思考的猴子13 天前
Unity VFX 属性 Postion 和 TargetPostion
unity
心前阳光14 天前
Unity资源导入之自动化资源导入
unity·自动化·游戏引擎
心前阳光14 天前
Unity之2021.3.45f2c1发布安卓程序遇到的问题
android·unity·游戏引擎
纪纯14 天前
PicoVR Unity Integration SDK 3.4 常用交互API
unity·游戏引擎·vr·pico
龙智DevSecOps解决方案14 天前
3A 游戏优化技术栈:如何打通引擎级分析工具与 DevOps 持续集成管线?
unity·性能优化·游戏开发·技术美术·perforce·unrealengine
葛兰岱尔14 天前
从 SolidWorks 到 Three.js,从 Inventor 到 Unity——制造业CAD模型“几何-语义一体化“转换,不再是天方夜谭!
开发语言·javascript·unity
世界很奇妙塔14 天前
AR/VR产业去泡沫后:从消费端娱乐,走向产业端全域赋能
ar·vr·娱乐