![]() ![]() The name can be changed to anything you like. ![]() You know that there's GameObject.Find which can be used to search for the gameobject's name. If every object should have it's own tag, i don't see why you not just use the name instead of a tag. Sometimes your data is already in a serialisable form.Īnd in my experience, due to the nature of serialising data, save systems are always fairly hard-coded. Tags are usually used to group similar objects or to identify (tag) it as part of that group. Of course this is only needed when you do have Unity data that needs to be converted in this way. If you have a monobehaviour/scriptable object that represents a player's inventory, that itself contains, for example, a list of more scriptable objects, you could have its serialisable surrogate counterpart have a constructor that takes in a runtime inventory, of which converts everything into a nicely serialisable form to be written out to JSON. You'll find a nice pattern to have, is, for each of your encapsulated runtime data classes, to have a serialisable surrogate counterpart - ergo, a class that converts strictly Unity runtime data into plain serialisable data, usually in the form of a struct or plain class - which has a constructor that takes its runtime counterpart.Ī good example is an inventory. One thing you could look at is constructors and the concept of serialisable surrogates. Naturally you'll continue to improve as you learn more about coding. Do you find the code more compact, readable, and maintainable? If so, then you've succeeded on improving yourself and your code. Welcome to the Unity Forums Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively. If you want to use PlayerPrefs to save your game, it's always better to use a JSON-based wrapper such as this one I forked from a fellow named Brett M Johnson on github:ĭo not use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers. ![]() and the Organisation of African Unity's (OAU), now the African Union (AU). Instead you must first create the MonoBehaviour using AddComponent() on a GameObject instance, or use ScriptableObject.CreateInstance() to make your SO, then use the appropriate JSON "populate object" call to fill in its public fields. 2003 (Act 653) to replace the provisions in the Criminal Procedure Code. The reason is they are hybrid C# and native engine objects, and when the JSON package calls new to make one, it cannot make the native engine portion of the object. When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. If you post a code snippet, ALWAYS USE CODE TAGS:Īn excellent discussion of loading/saving in Unit圓D by Xarbrough: Int randomRank = Random.Range (0, waypoints.Also, please be advised that photographs of code are not a thing. / Returns the transform of a random Waypoint. Waypoints = new Transform įor (int i = 0 i < gameObjects.Length i++)ĭebug.Log ($“ waypoint(s) found.”) GameObject gameObjects = GameObject.FindGameObjectsWithTag ("Waypoint") Public class WaypointManager : MonoBehaviour This empty is to be referenced in your enemy controller, so that the latter can get a random waypoint (or you can add a singleton if you prefer). The script is to be attached to an empty. I think the following code addresses your problem. ![]()
0 Comments
Leave a Reply. |