1.代码中定义public GameObject mySphere;
2.在Unity3D中将预制体拖至代码对应的mySphere的位置;
3.指定位置和旋转参数进行实例化;
4.具体实现代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeapGesture : MonoBehaviour
{
public GameObject mySphere;
Vector3 a = new Vector3(0, 0, 0); //实例化预制体的position,可自定义
Quaternion b = new Quaternion(0, 0, 0, 0);//实例化预制体的rotation,可自定义
// Use this for initialization
void Start ()
{
GameObject Sphere = GameObject.Instantiate(mySphere, a, b) as GameObject;
}
// Update is called once per frame
void Update ()
{
}
}

本文介绍如何在Unity3D中使用C#脚本实例化预制体,并提供了一个简单的示例,包括定义公共变量、设置实例化位置及旋转。

6056

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



