0
点赞
收藏
分享

微信扫一扫

悉见SDK 手机类型切换后的脚本切换/添加组件/删除组件

梅梅的时光 2022-04-14 阅读 29
unity

解决问题:

因为该SDK已经自动会识别用户手机类型,因为我需要为摄像机添加OutlineEffect这个脚本,以实现高亮显示,该脚本要求一次只能添加在一个摄像机上。

简单写个脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using cakeslice;//用于高亮显示的插件命名空间引用

public GameObject ARSessionHuaWei;
public GameObject ARSessionAndroidCam;

private void Start()
    {
        if (ARSessionHuaWei.activeSelf)
        {
            ARSessionHuaWei.transform.GetChild(0).gameObject.AddComponent<OutlineEffect>();

//通过Transform 类 获取物体第一个子对象,转换成游戏物体,在为其添加脚本组件
            Debug.Log("用户使用的是华为手机");
        }
        if (ARSessionAndroidCam.activeSelf)
        {
            Debug.Log("用户使用的是其他安卓手机,添加outline effect");                   ARSessionAndroidCam.transform.GetChild(0).gameObject.AddComponent<OutlineEffect>();
        }
}

------------------------------

移除组件的方法:

Unity在所有类中都没有提供移除组件的办法,没有RemoveComponet<>

移除方法是:


            Destroy(obj.GetComponent<Outline>());
            Destroy(obj.
GetComponent<Outline>());   

 

举报

相关推荐

0 条评论