// spaws void SpawnObject() { // get a random prefab from the object randomizer and instantiate it GameObject randomPrefab = (GameObject)prefabRandomizer.RandomObject(); GameObject newObject = (GameObject)Instantiate(randomPrefab, transform.position, transform.rotation); // if the normal map randomizer is in use, change the normal map of the object if (normalMapRandomizer != null && normalMapRandomizer.isActiveAndEnabled) { Texture randomNormalMap = (Texture)normalMapRandomizer.RandomObject(); newObject.GetComponent <Renderer>().material.SetTexture("_BumpMap", randomNormalMap); } // parent the object to the object spawner newObject.transform.parent = myTransform; // get the rigidbody Rigidbody newRigidBody = newObject.GetComponent <Rigidbody>(); // calculate force / direction vector to add Vector3 direction = Vector3.up; direction += new Vector3(Random.Range(-directionVariance, directionVariance), 0, Random.Range(-directionVariance, directionVariance)); direction.Normalize(); direction *= force; // calculate torque to add Vector3 torque = new Vector3(Random.Range(-maxTorque, maxTorque), Random.Range(-maxTorque, maxTorque), Random.Range(-maxTorque, maxTorque)); // add force and torque newRigidBody.AddForce(direction); newRigidBody.AddTorque(torque); }
public void SpawnCar() { GameObject car = (GameObject)Pool.RandomObject(); GameObject InstantiatedCar = Instantiate(car, transform.position, transform.rotation); }