本文整理汇总了C#中UnityEngine.Rigidbody.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.AddComponent方法的具体用法?C# Rigidbody.AddComponent怎么用?C# Rigidbody.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody
的用法示例。
在下文中一共展示了Rigidbody.AddComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
//Vector3 posChange = new Vector3(2, 2, 0);
// Use this for initialization
void Start()
{
//Creates the cube GameObject
GameObject cube = new GameObject();
//Works through creating the 8x8 wall of cubes
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
// The position I want the wall to start at (close to player)
float posX = 429.89f;
float posY = 0.528f;
float posZ = 229.5f;
//Moves the position of each box as the for loop goes through it
Vector3 position = new Vector3(posX + y * cubeW, posY + x * cubeH, posZ);
//My attempt at instantiation
//Rigidbody instanstiateCube = Instantiate(cube, transform.position = positionCube, transform.rotation) as Rigidbody;
//Actual creation of the cube as a cube game object
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
//Positions the new cube into the position of the position vector
cube.transform.position = position;
//Makes the cubes a rigidbody
Rigidbody gameObjectsRigidBody = cube.AddComponent<Rigidbody>();
//Changes the mass of the cubes
gameObjectsRigidBody.mass = 0.5f;
}
}
}
示例2: Start
//Vector3 posChange = new Vector3(2, 2, 0);
// Use this for initialization
void Start()
{
GameObject cube = new GameObject();
for (int x = 0; x < 9; x++)
{
for (int y = 0; y < 9; y++)
{
float posX = 430.0f;
float posY = 0.528f;
float posZ = 220.0f;
Vector3 position_ = new Vector3(posX + y * cubeW, posY + x * cubeH, posZ);
//Rigidbody instanstiateCube = Instantiate(cube, transform.position = positionCube, transform.rotation) as Rigidbody;
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = position_;
Rigidbody gameObjectsRigidBody = cube.AddComponent<Rigidbody>(); // Add the rigidbody.
gameObjectsRigidBody.mass = 0.5f;//Set the GO's mass to 1 via the Rigidbody.
}
}
}