2014-08-14 19:47:13|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网


Any of these options can be achieved with a single call to Instantiate(), you just have to hook it up to the right prefab and you're set!


The important part to remember is that the wreck which you Instantiate() can be made of completely different objects than the original. For example, if you have an airplane, you would model two versions. One where the plane consists of a single GameObject with Mesh Renderer and scripts for airplane physics. By keeping the model in just one GameObject, your game will run faster since you will be able to make the model with less triangles and since it consists of fewer objects it will render faster than using many small parts. Also while your plane is happily flying around there is no reason to have it in separate parts.


To build a wrecked airplane Prefab, the typical steps are:


  1. Model your airplane with lots of different parts in your favorite modeler  在你喜欢的模型里,利用不同的部分模拟的你飞机。
  2. Create an empty Scene  建立一个空白场景
  3. Drag the model into the empty Scene  拖动模型到这个空白场景
  4. Add Rigidbodies to all parts, by selecting all the parts and choosing  Component->Physics->Rigidbody


  1. Add Box Colliders to all parts by selecting all the parts and choosing Component->Physics->Box Collider

添加碰撞器盒到所有选取的部分和选择Component->Physics->Box Collider

  1. For an extra special effect, add a smoke-like Particle System as a child GameObject to each of the parts  对于一个额外的效果,添加一个烟雾模拟粒子系统作为子GameObject到每个部分。
  2. Now you have an airplane with multiple exploded parts, they fall to the ground by physics and will create a Particle trail due to the attached particle system. Hit Play to preview how your model reacts and do any necessary tweaks.


  1. Choose Assets->Create Prefab  选择Assets->Create Prefab
  2. Drag the root GameObject containing all the airplane parts into the Prefab


var wreck : GameObject;

// As an example, we turn the game object into a wreck after 3 seconds automatically

function Start () {

    yield WaitForSeconds(3);



// Calls the fire method when holding down ctrl or mouse

function KillSelf () {

    // Instantiate the wreck game object at the same position we are at

    var wreckClone = Instantiate(wreck, transform.position, transform.rotation);

    // Sometimes we need to carry over some variables from this object

    // to the wreck

    wreckClone.GetComponent(MyScript).someVariable = GetComponent(MyScript).someVariable;

    // Kill ourselves



The First Person Shooter tutorial explains how to replace a character with a ragdoll version and also synchronize limbs with the last state of the animation. You can find that tutorial on the Tutorials page.

发表评论0条 】