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);
        }
    }

四、效果

相关推荐
沉默金鱼2 小时前
Unity实用技能-格式化format文字
ui·unity·游戏引擎
jyy_992 小时前
通过网页地址打开unity的exe程序,并传参
unity
本妖精不是妖精6 小时前
基于 Rokid Max 与 JSAR 构建空间锚定型 AR 信息面板
后端·ar·restful
qq_2052790516 小时前
Unity TileMap 使用经验
unity·游戏引擎
心灵宝贝19 小时前
Mac Unity 2018.dmg游戏工具 安装步骤 简单易懂教程(附安装包)
macos·unity·游戏引擎
Q***l68720 小时前
Vue增强现实案例
前端·vue.js·ar
TO_ZRG20 小时前
Unity SDK 通过 Registry 分发及第三方依赖处理指南
unity·游戏引擎
todoitbo1 天前
基于Rokid CXR-M SDK实现AR智能助手应用:让AI大模型走进AR眼镜
人工智能·ai·ar·ar眼镜·rokid
龙智DevSecOps解决方案1 天前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
WarPigs2 天前
Unity编辑器开发笔记
unity·编辑器·excel