
Unity Development Best Practices and Tips
Learn essential Unity development practices such as handling player preferences, loading scenes efficiently, and managing runtime activation and enabling of game objects. Understand the importance of avoiding data duplication and the use of PlayerPrefs for persistent storage. Enhance your Unity skills with these valuable insights.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
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
Dont 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;