Player preferences, Loading Scenes, Activating and Enabling Unity Notes Player preferences, Loading Scenes, Activating and Enabling
Review Camera size is ½ screen height and width. Images often have 100:1 pixel to unit ratio In 2D, z value is used for layering Object positions are world space for parents, object space for children Fields can be serialized rather than public Attaching BoxColliders registers objects for collision events
Player Preferences File stored on disk by unity Keep player preferences between plays It’s really a hashtable
Using preferences bool PlayerPrefs.HasKey(String key) void PlayerPrefs.SetInt(String key, int value) void PlayerPrefs.SetFloat(String key, float value) void PlayerPrefs.SetString(String key, String value) int PlayerPrefs.GetInt(String key) etc…
Don’t duplicate data Usually a bad idea to store things in 2 different places – why? Don’t re-keep data in local variable without a good reason
Loading Scenes need using statement: using UnityEngine.SceneManagement; SceneManager is static object void SceneManager.LoadScene(String sceneName);
Runtime activation GameObjects can be activated and de-activated in code: gameObject.SetActive(false); When might you want to do this? You can check status as well: bool isActive = gameObject.activeSelf;
Runtime enabling Maybe you don’t want the whole object de-activated, but you do want to enable or disable one component of the object: myComponent = GetComponent<Whatever>(); myComponent.enabled = true;