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上

三、效果

相关推荐
玖玥拾19 小时前
C# 语言进阶(十四)Unity UI界面开发 + 网络消息联动
服务器·开发语言·网络·ui·unity·c#·游戏引擎
hjjdebug20 小时前
ar 工具及 ar 库格式研究
ar·文档工具·ar_parse
野区捕龙为宠20 小时前
Unity 持久化数据
unity·游戏引擎·lucene
船漏了就会沉1 天前
AprilTag:让机器“看见”世界坐标的视觉路标
ar·无人机
郝学胜-神的一滴1 天前
[简化版 GAMES 101] 计算机图形学 17:纹理技术从基础原理到多场景实战应用
c++·unity·游戏引擎·图形渲染·three.js·opengl·unreal
_ZHOURUI_H_2 天前
MyFramework: 同样是 Unity 游戏开发框架,和 HTFramework 的设计取向有什么不同?(下)
unity·游戏引擎·游戏开发·游戏ui·手游开发
小刘数字化3 天前
告别爬塔危险:AR眼镜如何重构电力高空巡检安全标准
安全·重构·ar
北京阿法龙科技有限公司3 天前
AR智能眼镜安防应用核心指标:识别距离筑牢防线
java·开发语言·ar
丁小未3 天前
基于MVVM框架的XUUI 扩展的UI管理系统教程
unity·mvvm·ui框架·xuui·ui管理器
私人珍藏库3 天前
[Android] PeakFinder AR v4.8.89 (山峰全景识别+增强现实山峰查看器)
android·人工智能·智能手机·ar·工具·软件