本文介绍了如何在Unity C#代码的GameObject.CreatePrimitive中添加.fbx(人类3D对象)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我问过问题,并获得了添加和在运行时销毁3D对象.

Previously I asked question and got proper solution for adding and destruction 3D object at run time.

通过使用 GameObject.CreatePrimitive(PrimitiveType.Capsule); ,我只能添加有限的3D对象,例如 Cube,Capsules和其他

By using GameObject.CreatePrimitive(PrimitiveType.Capsule); I can add only limited 3D object like Cube , Capsules and other

现在的问题是,我要添加3D人体 .fxb 对象.我可以在下面的代码中添加 .fbx 对象吗?

Now the problem is, I want add 3D human body .fxb object. Can I add .fbx object in below code?

Queue<GameObject> Capsules;
void Start()
{
    Capsules = new Queue<GameObject>();
}

public GameObject caps;
private void createObject()
{
    caps = GameObject.CreatePrimitive(PrimitiveType.Capsule);
    Capsules.Enqueue(caps);
}

推荐答案

您可以使用预制件.在编辑器中创建预制件之后您可以使用以下代码在脚本中使用它:

You can do this by using prefabs. After you created your prefab in the editoryou can use it in scripts using the following code:

using UnityEditor;

// Loading the prefab this way only works in the editor.
GameObject myPrefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Prefabs/Character.prefab");

// Use this otherwise:
// using UnityEngine;
// GameObject myPrefab = Resources.Load<GameObject>("Prefabs/Character");
// Note: The Prefabs folder has to be placed in a folder named Resources.

在装载预制件后,可以使用Instantiate进行复制.

after you have your prefab loaded you can make copies using Instantiate.

GameObject character = Object.Instantiate(myPrefab);
// Set location, rotation, ...
Capsules.Enqueue(character);

这篇关于如何在Unity C#代码的GameObject.CreatePrimitive中添加.fbx(人类3D对象)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:51