title | category | layout | tags | prism_languages | ||
---|---|---|---|---|---|---|
GameObject |
Scene |
2017/sheet |
|
|
// Create a GameObject
Instantiate(GameObject prefab);
Instantiate(GameObject prefab, Transform parent);
Instantiate(GameObject prefab, Vector3 position, Quaternion rotation);
Instantiate(bullet);
Instantiate(bullet, bulletSpawn.transform);
Instantiate(bullet, Vector3.zero, Quaternion.identity);
Instantiate(bullet, new Vector3(0, 0, 10), bullet.transform.rotation);
GameObject.Find("NAME IN HIERARCHY");
GameObject.FindWithTag("TAG");
GameObject.FindGameObjectWithTag("TAG");
GameObject.FindGameObjectsWithTag("TAG");
GameObject.FindObjectOfType<Rigidbody>();
GameObject.FindObjectsOfType<Rigidbody>();
// Get first child GameObject
parentGameObject.transform.GetChild(0);
// Add Component to GameObject
gameObject.AddComponent<Rigidbody>();
// Get Component from GameObject
gameObject.GetComponent<Rigidbody>();
Destroy(gameObject);
// Do not destroy the target Object when loading a new Scene
DontDestroyOnLoad(gameObject);
// Current GameObject
Rigidbody rb = GetComponent<Rigidbody>();
Rigidbody[] rb = GetComponents<Rigidbody>();
// Children
Rigidbody rb = GetComponentInChildren<Rigidbody>();
Rigidbody[] rb = GetComponentsInChildren<Rigidbody>();
// Parent
Rigidbody rb = GetComponentInParent<Rigidbody>();
Rigidbody[] rb = GetComponentsInParent<Rigidbody>();
Both the Rigidbody and the targeted GameObject needs to have a Collider
attached. If they have the Physics will interact and the OnCollisionEnter()
event will trigger.
rb.AddForce(Vector3.up * 10, ForceMode.Impulse);
Adds a jump/force to the Rigidbody in a Y-axis direction.