为了账号安全,请及时绑定邮箱和手机立即绑定

如何将3D模型动态添加到地平面

如何将3D模型动态添加到地平面

C#
慕娘9325324 2021-05-07 18:14:23
我正在使用Unity的地平面功能放置3D动画模型。但是,我现在正在使用AssetBundle功能下载此3d模型,并需要使用脚本将其放置在Ground Plane Stage上。但是,当我将其部署到android设备上时,它不会显示...我正在使用支持GroundPlane检测的Xiaomi Redmi 3s。我已添加脚本以将资产捆绑包下载到“平面查找器”中AssetbundleDownloadingScript:public class AssetLoader : MonoBehaviour{    public static AssetLoader Instance;    public string url = "myurl";    public int version = 1;    public string AssetName;    //public Text infoText;    public string infoText = "";    AssetBundle bundle;    void Awake()    {        Instance = this;        DownloadAsset();    }    void OnDisable()    {        //AssetBundleManager.Unload(url, version);    }    public void DownloadAsset()    {        // bundle = AssetBundleManager.getAssetBundle (url, version);        //   Debug.Log(bundle);        if (!bundle)            StartCoroutine(DownloadAssetBundle());    }    IEnumerator DownloadAssetBundle()    {        yield return StartCoroutine(AssetBundleManager.downloadAssetBundle(url, version));        bundle = AssetBundleManager.getAssetBundle(url, version);        if (bundle != null)            infoText = "Download Success.....";        else            infoText = "Download error please retry";        GameObject santaasset = bundle.LoadAsset("animation_keyframes_increase_v1", typeof(GameObject)) as GameObject;        //here script attached to plane finder,get 1st child of planefinder        var child = gameObject.transform.GetChild(0);        if (santaasset != null)        {            santaasset.transform.transform.Rotate(new Vector3(0, 180, 0));            santaasset.transform.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);            santaasset.transform.transform.SetParent(child.transform, false);        }        bundle.Unload(false);    }    public void SetInfoText(string text)    {        //infoText.text = text;    }    void OnGUI()    {        GUILayout.Label("Dummy Label:" + infoText);    }}这是我的场景的屏幕截图:关于我在做什么错的任何建议吗?谢谢。
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

我在您发现AssetbundleDownloadingScript您正在创建中时注意到GameObject santaasset,但是您绝不会将对象分配给new或现有的GameObject甚至是Instantiating它。您要分配的Asset是您正在从中加载的bundle。但是,该资产也从未分配过,因为它只是被加载到内存中,因此Unity可以识别它。这就是您所经历的,这就是为什么您在游戏中看到该对象,但该对象未激活,甚至很难禁用的原因。

若要解决此问题,您必须像这样分配您的GameObject或实例化它:
GameObject santaasset = Instantiate(bundle.LoadAsset("animation_keyframes_increase_v1", typeof(GameObject)) as GameObject);


查看完整回答
反对 回复 2021-05-16
  • 1 回答
  • 0 关注
  • 155 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号