I can again think of some solutions like a SpellContainer class for each Spell which is essentially a Singleton or Scriptable Object which contains the prefab and other spell attributes as a field, and would contain the Cast method there instead. so I could have these things configurable on a per-spell basis, but this doesn't really work well either as I have to Instantiate the spell first before I can access all these attributes that I've configured on the FireBall or IceBall prefab, and then I would have to delay enabling things like the spell "MoveForward" script, its mesh-renderer etc. It would handle things like what player animation is played, the spawn position of the spell etc., how long it takes to spawn after casting, its cooldown, speed etc. The spell script would contain a "Cast()" method which seemed natural. With my Spell class I'm facing a similar issue in that I wanted a FireBall and IceBall prefab with a Spell script/class attached to it. Could then separate the OnTrigger method into a new script called "Collectable" which is what handles destroying the prefab and adding the ScriptableObject to the inventory.īut I feel like I'm missing something here and these solutions feel hacky. Create a ScriptableObject container class which contains an ItemPrefab field, a SpellSpeedModifier attribute and other things. Create a new "CollectedItem" class/object that is created from the item on pickup and passed to the Inventory before the Item script is destroyed. Disable the mesh-render/box-collider of the Prefab instead of destroying it In this particular instance I can think of quite a few solutions Of course the issue here is once I destroy the prefab, the Item script gets destroyed along with it. It has a OnTrigger event that adds this item to the players inventory and destroys the prefab. I've instinctively attached to it an "Item" script to it which has an "ApplyEffects(Spell spell)" method on it and modifies the speed of the spell when its cast. So I have a SpellSpeedUp prefab - it makes spells move faster when the Player picks it up. I've been making a simple game where you can pick up items and new spells. I've also just found out about ScriptableObjects so trying to wrap my head around their use-case. Trying to wrap my head around something that feels like it should be pretty straight forward and obvious, especially as someone who is experienced in OO, but would appreciate have more experienced Unity devs view on this. Hey everyone! I'm an experienced programmer, but new to game/unity dev. Reddit Logo created by /u/big-ish from /r/redditlogos! Long series.ĬSS created by Sean O'Dowd, Maintained and updated by Louis Hong /u/loolo78 Favors theory over implementation but leaves source in video description. Normally part of a series.Īlmost entirely shader tutorials. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Using Version Control with Unit圓d (Mercurial) Related SubredditsĬoncise tutorials. Unity Game Engine Syllabus (Getting Started Guide)ĥ0 Tips and Best Practices for Unity (2016 Edition) Lots of professionals hang out there.įreeNode IRC Chatroom Helpful Unit圓D Links Use the chat room if you're new to Unity or have a quick question. Please refer to our Wiki before posting! And be sure to flair your post appropriately. Remember to check out /r/unity2D for any 2D specific questions and conversation! A User Showcase of the Unity Game Engine. My usual approach with editor scripts is to create a SerializedProperty for each variable that I want to expose and use serializedObject.FindProperty("_myVariableName") after setting the serializedObject.targetObject as the name of my script.Īs I want to change the pixelsPerUnitMultiplier on the image component of the gameObject in my scene by simply pressing a custom button in its inspector I first created a function in the UIButton class that would handle the functionality.News, Help, Resources, and Conversation. (I have attached a picture to demonstrate what I want to achieve) ![]() ![]() This is necessary as I want to reuse the same button prefab but have it look consistent in its pixelarted look among many sizes. I have hit a pretty major roadblock while trying to create a button that dynamically sets the pixel per unit multiplier on the image component of the visuals of my button. I have been getting into editor scripting while creating my own custom versions of generic UI elements to avoid dropping yet another project due to frustration regarding UI stuff.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |