Vuforia AR篇(三)— AR模型出场效果

目录


前言

在这个数字化日益增长的时代,增强现实(AR)技术正以前所未有的速度发展。AR模型,作为这一技术的核心组成部分,不仅改变了我们与数字世界的互动方式,还极大地丰富了我们的现实体验。本文将探讨AR模型的出场效果。


一、AR模型出场

创建ARCamera和ImageTarget

导入一个带动画的模型

复制下面的脚本

然后改名成下面DeathObserverEventHandler

找到下面的2个方法

重写下面的2个方法

csharp 复制代码
    protected virtual void OnTrackingFound()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(true);
        //
        //
        //
        // OnTargetFound?.Invoke();
        GameObject death = Instantiate(deathPrefab, transform, true);
        death.name = "Death";
        death.transform.position = transform.position;
    }

    protected virtual void OnTrackingLost()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(false);
        //
        //
        // OnTargetLost?.Invoke();
        GameObject death = GameObject.Find("Death");
        if (death != null)
        {
            Destroy(death);
        }

    }

然后挂上脚本

二、AR出场特效

导入特效素材

添加特效代码

csharp 复制代码
    protected virtual void OnTrackingFound()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(true);
        //
        //
        //
        // OnTargetFound?.Invoke();
        GameObject death = Instantiate(deathPrefab, transform, true);
        death.name = "Death";
        death.transform.position = transform.position;
        GameObject effect = Instantiate(effectPrefab, transform, true);
        effect.name = "Effect";
        effect.transform.position = transform.position;
    }

    protected virtual void OnTrackingLost()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(false);
        //
        //
        // OnTargetLost?.Invoke();
        GameObject death = GameObject.Find("Death");
        if (death != null)
        {
            Destroy(death);
        }

        GameObject effect = GameObject.Find("Effect");
        if (effect != null)
        {
            Destroy(effect);
        }
    }

三、添加过渡效果

csharp 复制代码
    private void Update()
    {
        _death.transform.localPosition = Vector3.Lerp(_death.transform.localPosition , Vector3.zero, Time.deltaTime);
        _death.transform.localScale = Vector3.Lerp(_death.transform.localScale , new Vector3(0.4f, 0.4f, 0.4f), Time.deltaTime);
    }

    protected virtual void OnTrackingFound()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(true);
        //
        //
        //
        // OnTargetFound?.Invoke();
         _death = Instantiate(deathPrefab, transform, true);
        _death.name = "Death";
        
        
        GameObject effect = Instantiate(effectPrefab, transform, true);
        effect.name = "Effect";
        effect.transform.position = transform.position;
    }


    protected virtual void OnTrackingLost()
    {
        // if (mObserverBehaviour)
        //     SetComponentsEnabled(false);
        //
        //
        // OnTargetLost?.Invoke();
        GameObject death = GameObject.Find("Death");
        if (death != null)
        {
            Destroy(death);
        }

        GameObject effect = GameObject.Find("Effect");
        if (effect != null)
        {
            Destroy(effect);
        }
    }

四、效果

相关推荐
lrh30255 小时前
Custom SRP - Complex Maps
unity·srp·render pipeline
m0_497214159 小时前
unity中通过拖拽,自定义scroll view中子物体顺序
unity·游戏引擎
地狱为王12 小时前
在Unity中实现DTLN-AEC处理音频文件的功能
unity·aec·降噪
北京阿法龙科技有限公司16 小时前
AR 巡检与普通巡检有哪些区别,有哪些优势|阿法龙XR云平台
ar·xr
SmalBox18 小时前
【URP】Shader绘制棋盘格对比内置管线
unity·渲染
Teamhelper_AR2 天前
AR技术:电力巡检的智能升级之路
ar
EQ-雪梨蛋花汤2 天前
【Unity笔记】Unity 编辑器扩展:打造一个可切换 Config.assets 的顶部菜单插件
unity·编辑器·游戏引擎
Teamhelper_AR2 天前
AR技术:多行业数字化转型的加速引擎
ar
SmalBox2 天前
【URP】UnityHLSL顶点片元语义详解
unity·渲染
蜀中廖化2 天前
Griffin|增强现实数据集|无人机数据集
ar·无人机