当前位置:网站首页>Vuforia for Unity 添加按钮实现模型放大缩小
Vuforia for Unity 添加按钮实现模型放大缩小
2022-06-09 15:15:00 【djc8小码农】
具体是将脚本附加到预制件prefab上。
做法如下
将Vuforia for unity 导入到Unity中后,定位到Vuforia提供的预设预制件上。
有如下的预制件:ARCamera、CloudRecognition、CylinderTarget、FrameMarker、ImageTarget、Multitarget、ObjectTarget、TextRecognition、UserDefinedTarget、VirtualButton、Word。
我们这里以ImageTarget预制件来做例子
在Assets中添加一个C#脚本(C# Script),取名为BtnControl,脚本代码下面附加上。
解释下我这个脚本,我这个脚本通过调用GUI.Button()方法,在屏幕上绘制按钮,点击按钮后,可以对模型进行放大以及缩小,脚本写的很粗糙。见谅。
点击预制件ImageTarget,然后在右侧的Inspector上点击Add Component
输入脚本名:BtnControl(注:当你输入的时候,应该会自动联想到这个文件),之后回车
然后就可以开始将预制件拖到Hierarchy上开始使用吧。 BtnControl.cs脚本代码如下
using UnityEngine;
using System.Collections;
public class BtnControl: MonoBehaviour {
void OnGUI() {
if (GUI.Button(new Rect(10, 50, 200, 50), "放大"))
{
Vector3 v3 = transform.localScale;
transform.localScale = new Vector3(v3.x*1.2f, v3.y*1.2f, v3.z*1.2f);
}
if (GUI.Button(new Rect(10, 120, 200, 50), "缩小"))
{
Vector3 v3 = transform.localScale;
transform.localScale = new Vector3(v3.x/1.2f,v3.y/1.2f,v3.z/1.2f);
}
}
} 边栏推荐
- 数组去重
- Mysql+C# EF6间的连接
- 利用Redis进行数据缓存的项目实践
- Geoffrey Hinton最新访谈:不出五年,我们就会破解大脑的运作机制,但不是通过反向传播
- Linux runs shengxunwei online customer service system: implementation method of supporting SQL server and MySQL at the same time
- 王兴张勇徐雷,谁能问鼎本地电商?
- 134. 加油站
- EasyExcel-合并单元格
- BAT和FAANG的时代翻篇儿了,谁来接棒?
- [paper] cascade rpn: delving into high quality region proposal network with adaptive revolution
猜你喜欢

华为哈勃将再添IPO,美芯晟蛰伏十余年后冲刺科创板

各厂商的数据湖解决方案

Connection between mysql+c ef6

博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现

我把自动化测试学完后,一个月拿了2w+,才知道自动化测试这么吃香

【五、反向代理及其相关配置】

I learned that automated testing is so popular after I got 2w+ in a month

QT MSVC compiler Chinese problem solving, Chinese garbled and unable to compile normally

135. 分发糖果

C#/VB.NET 在Word转PDF时生成目录书签
随机推荐
js项目中常用的一些工具函数
最成功也最差劲的CEO去世,索尼还是走在他的老路上
pixi.js 平铺背景
淘宝小程序 2048游戏
数据库中错误1062,报错
Due to the suspension of Russian business: IBM Q1 lost 2billion, Cisco 1.3 billion, Adobe 500million, HP 6.7 billion, uipath 100million
你好,欢迎访问我的博客
一年进账34.46亿,又一个福建老乡要IPO了
酒店长租是一门好生意吗?
3 个技巧来破解你可以立即使用的 Flutter 生产力!
百度一程序员被判:不满他人接手项目、彰显自己作用、多次对数据库进行删改,犯破坏计算机信息系统罪
[Typecho blog Xiaobai building tutorial] you are only one step away from having your own blog
全球骨干网中断 4 小时:谷歌云、AWS、Azure 等均受到影响
ARM64 上的性能怪兽:API 网关 Apache APISIX 在 AWS Graviton3 上的安装和性能测试
道友,日增量百万级业务该如何进行数据设计呢?
[IV. demand analysis of several Internet enterprises based on domain name]
Halodoc's key experience in building Lakehouse using Apache Hudi
JS implements the method of copying contents to the clipboard
Halodoc使用 Apache Hudi 构建 Lakehouse的关键经验
3ds max 错误提示1603,vc2005安装失败,错误排查