Unity3D中通过代码自动为GameObject添加相应的组件
在Unity3D中运行时,为某些GameObject添加一些组件,比如:刚体、GUITexture等等。方法一:在代码的开头添加以下语句即可:RequireComponent(typeof(GUIText))]
public class HappinessInFrontOfUs : MonoBehaviour {
}
方法二:例如:给一个名为Sound的OBJ添加声源,然后把它放到另一个OBJ的体内GameObject Sound = new GameObject("Sound");
Sound.AddComponent<AudioSource>();
Sound.transform.parent = 想要作为父物体的.transform;
Sound.transform.localPosition = Vector3.zero;
很不错 难得一见的好帖 说的非常好 不错不错 LZ真是人才 楼主是超人 真心顶 难得一见的好帖 说的非常好