
作用:添加组件,如:刚体组件、C#脚本
using System.Collections;using System.Collections.Generic;using UnityEngine;public class shoot : MonoBehaviour{public GameObject B;// Start is called before the first frame updatevoid Start(){GameObject a = GameObject.Instantiate(B);GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);b.AddComponent<Rigidbody>();}// Update is called once per framevoid Update(){}}
using System.Collections;using System.Collections.Generic;using UnityEngine;public class shoot : MonoBehaviour{public GameObject B;// Start is called before the first frame updatevoid Start(){GameObject a = GameObject.Instantiate(B);GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);b.AddComponent<Rigidbody>();//添加刚体组件}// Update is called once per framevoid Update(){}}
1。注意名称,这里是shoot