作用:创建物体Instantiate
应用:开枪,就是点击鼠标,在物体A的某个位置,创建B
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot : MonoBehaviour
{
public GameObject B;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GameObject a = GameObject.Instantiate(B);//实例化
GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot : MonoBehaviour
{
public GameObject B;//生成/实例化的东西:B
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GameObject a = GameObject.Instantiate(B);//实例化
GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);//实例化,位置在目标的位置,目标的旋转角度
}
}
1.把脚本拉到要生成/实例化东西的A
2.添加要发射的B,一般是已经做好的东西
添加Rigibody刚体/C#脚本
a.AddComponent<Rigibody>();