public static GameObject Instantiate(string name, Vector3 position, Quaternion rotation, Vector3 linearVelocity) { GameObject tocopy = Prefabs.GetPrefab(name); if (tocopy == null) { Debug.LogError("Prefab not found"); return(null); } GameObject result = (GameObject)tocopy.Clone(); result.transform.position = position; result.transform.rotation = rotation; //if (tocopy.transform.isStatic) result.transform.SetStatic(); result.Awake(); result.Start(); // because instantiated at runtime // If it is a dynamic rigid body it cna have some linear velocity when instantiated if (result.HasComponent <DynamicRigidBody>()) { DynamicRigidBody dc = result.GetComponent <DynamicRigidBody>(); dc.RigidBody.LinearVelocity = Conversion.ToJitterVector(linearVelocity) * 5; dc.RigidBody.AddTorque(Conversion.ToJitterVector(linearVelocity) * 5); } return(result); }
// --------------------- BASE METHODS ------------------ public override void Start() { base.Start(); transform.rotation = MyRandom.YRotation(); if (gameObject.HasComponent <DynamicRigidBody>()) { _rigidBody = gameObject.GetComponent <DynamicRigidBody>(); } }