Object.Instantiate 实例
static function Instantiate (original : Object,position : Vector3, rotation : Quaternion) : Object
Description描述
Clones the object original and returns the clone.
克隆原始物体并返回克隆物体。
Clones the object original, places it at position and sets the rotation to rotation, then returns the cloned object. This is essentially the same as using duplicate command (cmd-d) in Unity and then moving the object to the given location. If a game object, component or script instance is passed, Instantiate will clone the entire game object hierarchy, with all children cloned as well. All game objects are activated.
克隆原始物体,位置设置在position,设置旋转在rotation,返回的是克隆后的物体。这实际上在Unity和使用复制(ctrl+D)命令是一样的,并移动到指定的位置。如果一个游戏物体,组件或脚本实例被传入,实例将克隆整个游戏物体层次,以及所有子对象也会被克隆。所有游戏物体被激活。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform

本文介绍了Unity中的Object.Instantiate方法,用于克隆游戏物体、组件或脚本实例。详细阐述了不同参数的用法,包括设置克隆物体的位置和旋转,以及如何在克隆后设置组件属性。常见应用场景包括创建投射物、AI敌人和粒子效果。
最低0.47元/天 解锁文章
3410

被折叠的 条评论
为什么被折叠?



