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

四、效果

相关推荐
神码编程18 小时前
【Unity】MiniGame编辑器小游戏(十五)中国象棋局域网对战【Chinese Chess】(上)
unity·编辑器·游戏引擎·小游戏
伽蓝_游戏18 小时前
第四章:AssetBundle 核心机制与文件结构
unity·c#·游戏引擎·游戏程序
郝学胜-神的一滴18 小时前
中级OpenGL教程 006:高光反射原理与 Shader 实现
c++·unity·godot·图形渲染·three.js·opengl·unreal
神码编程1 天前
【Unity】MiniGame编辑器小游戏(十六)中国象棋局域网对战【Chinese Chess】(下)
unity·编辑器·游戏引擎·小游戏
Maddie_Mo1 天前
Unity 联动 Trae AI 项目开发基础教学
人工智能·unity·游戏引擎
新手unity自用笔记1 天前
unity简单新手上手动画系统讲解
unity·游戏引擎
伽蓝_游戏1 天前
第二章:深入 Unity 资源导入管线 (Asset Import Pipeline)
游戏·unity·c#·游戏引擎·游戏程序
ykjhr_3d2 天前
广州虚拟展厅ar定制开发推荐
ar·虚拟展厅·数字展厅·ar虚拟展厅
我寄人间雪满头丶2 天前
Unity中对于数值游戏的大数显示
游戏·unity·游戏引擎
游乐码2 天前
unity基础 (三)坐标系
unity·游戏引擎