用EasyAR SDK 来开发好玩的应用
前言:
EasyAR 开发群:605785368
AR开发者社区:

第一部分:预览
用EasyAR SDK 给你一个AR 效果的礼物

资源:
链接:https://pan.baidu.com/s/1nuEhhNz密码: vq1j
第二部分:开发环境准备
关于用EasyAR SDK 搭建AR 开发环境的教程,我已经写过很多了,不懂得朋友可以看下我之前的教程。我们直接讲解本章的核心内容。
我们下好资源后,导入到unity,搭建好基本AR环境。如图:

第三部分:模型的搭建
我们将准备好的资源--礼物与二次元女生导入到unity中,并将三个礼物盒子与女主角拖入到ImageTarget 充当子物体,礼物盒的模型位置在

女主角的模型位置在

拖入之后,根据自己的需求修改其位置,实现其如下效果:


第四部分:编写脚本
首先为礼物盒添加Box Collider,并勾选Trigger

新建脚本,名字随便起,先实现点击礼物盒后,礼物盒消失二次元女生出现,这里用到了一个最巧但最常用方便呢的方法Void OnMouseDown(),使用这个方法前提是该物体挂了个Collider
void OnMouseDown()
{
Destroy(this.gameObject);
}
第五部分:添加粒子特效
使用粒子特效来使得更令人惊喜的礼物效果,粒子特效的资源位置在

接下来,编写脚本,脚本比较简单,基本思路就是在点击礼物盒子后,盒子销毁,创建粒子特效,代码如下:
using UnityEngine;
using System.Collections;
public class Explore : MonoBehaviour {
public GameObject explore1;
public GameObject explore2;
public GameObject explore3;
public AudioSource sound;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseDown()
{
Destroy (this.gameObject);
Instantiate (explore1,transform.position,transform.rotation);
Instantiate (explore2, transform.position, transform.rotation);
Instantiate (explore3,transform.position,transform.rotation);
}
}
粒子的选择与自己的喜好来选择,不一定和我一样,这样大家可以实现不同的效果。
第六部分:添加音效
音效对一个应用或游戏给人的用户体验影响还是很大的,给礼物盒子添加AudioSource

using UnityEngine;
using System.Collections;
public class Explore : MonoBehaviour {
public GameObject explore1;
public GameObject explore2;
public GameObject explore3;
public AudioSource sound;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseDown()
{
Destroy (this.gameObject);
sound.Play ();
Instantiate (explore1,transform.position,transform.rotation);
Instantiate (explore2, transform.position, transform.rotation);
Instantiate (explore3,transform.position,transform.rotation);
}
}
OK,就是这样,用很简单的代码就可以用EasyAR SDK 开发出惊艳的应用。