首页 > 代码库 > unity 使用代码创建子弹
unity 使用代码创建子弹
//前提是创建子弹预制体,把预制体拉进BulletPrefab里面
using UnityEngine;
using System.Collections;
public class game : MonoBehaviour {
public GameObject BulletPrefab;
// Update is called once per frame
void Update () {
//创建子弹
GameObject bullet = Instantiate(BulletPrefab, Vector3.zero, Quaternion.identity) as GameObject;
//1秒销毁子弹
Destroy(bullet,1);
}
}
unity 使用代码创建子弹