Manual: Important classes - GameObject
MonoBehaviour
Awake()
DoStuffThatWeWant()
Start
Update
Start()
Update()
FixedUpdate()
LateUpdate()
Time.time
Time.deltaTime
deltatime = 1 / FPS
Vector3 velocity = new Vector3(speed * Time.deltaTime, 0.0f, 0.0f); transform.position += velocity;
velocity
public
[SerializeField]
[Header("Explainer for UI")]
[Range(x,x)]
gameObject
parentGameObject.transform.GetChild(indexNumber).gameObject
parentGameObject.transform.Find("childName").gameObject
childGameObject.transform.parent
Instantiate()
GameObject newObject = Instantiate(bullet, transform.position, transform.rotation);
Destroy()
Destroy(bullet, 2.0f);
gameObject.SetActive(false);
myObject.activeSelf
false
true
myObject
myObject.activeInHierarchy
OurComponentType ourComponent = ourGameObject.GetComponent<OurComponentType>();
Rigidbody rb = playerObject.GetComponent<Rigidbody>();
Rigidbody rb = GetComponent<Rigidbody>();
It's a good idea to check if a component exists before actully using it
Rigidbody rb = GetComponent<Rigidbody>(); if (rb != null) { // do stuff with rb }
if (playerObject.TryGetComponent<RigidBody>(out RigidBody rb)) { // do stuff with rb }
component.enabled = true;
component.enabled = false;
component.enabled = !component.enabled
myGameObject.tag
GameObject.FindWithtag("tagname");
GameObject.FindGameObjectsWithTag("tagname");
private void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.tag == "Collectible") { Destroy(other.gameObject); }
Create a Scene with following GameObjects:
Spoiler: For a click response, you can use this method:
void OnMouseOver() { if (Input.GetMouseButtonDown(0) { // Do stuff } }